> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# opacity

APISummary
## 介绍

opacity 属性用 0 \~ 1 的数字描述对象的不透明度，1 为完全不透明，0 为完全透明，默认值为 1。改属性会影响其所有的子元件。

:::caution
opacity 会造成离屏渲染，在 iOS 和 Android 上都会有性能损失。同时，Android 上会造成 `overflow:visible` 失效，可以使用 `overlap={false}` 规避，
但会造成背景和内容的透明度分离。

需要使用 `overlap-ios` 和 `overlap` 来控制 iOS 和 android 上的背景与内容的透明度组合行为。由于平台限制，iOS 默认为 false，
android 默认为 true。

:::

## 使用示例

**下面是一个示例: css-api**

**Entry:** `src/opacity`
**Bundle:** `dist/opacity.lynx.bundle`

```tsx
import { root } from "@lynx-js/react";
import "./index.scss";

import image from "../../resource/lynx.png";

const Opacity = () => {
  const heightStyle = {
    height: "10px",
  };

  const opacity1Style = {
    opacity: 1,
  };

  const opacity05Style = {
    opacity: 0.5,
  };

  const opacity0Style = {
    opacity: 0,
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="fixed_area">
        <image className="relative_image" src={image}></image>
        <view style={heightStyle}></view>
        <image className="relative_image" style={opacity1Style} src={image}></image>
        <view style={heightStyle}></view>
        <image className="relative_image" style={opacity05Style} src={image}></image>
        <view style={heightStyle}></view>
        <image className="relative_image" style={opacity0Style} src={image}></image>
      </view>
    </scroll-view>
  );
};

root.render(<Opacity />);

```

v0.11.0



## 语法

```css
/* 完全不透明 */
opacity: 1;

/* 半透明 */
opacity: 0.5;

/* 完全透明 */

opacity: 0;
```

### 取值

- `<number>`
  number 是一个 `0.0` \~ `1.0` 的数字，

- 默认值
  **1**

|  数值  |   效果  |
| :--: | :---: |
|   1  |  完全显示 |
| 0\~1 | 添加透明度 |
|   0  |  不显示  |

## 形式定义

| 初始值 | 1 |
| 适用元素 | all elements |
| 是否支持继承 | no |
| 是否支持动画 | yes |


## 形式语法

opacity: `<number>`;

## 与 Web 的区别

与 web 相同。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.opacity`

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/23-opacity.json) · [MDN](https://developer.mozilla.org/zh-CN/docs/Web/CSS/opacity)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| opacity | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |

**`opacity`**

**Specifications:**

