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

# transform

APISummary
## Introduction

The transform CSS property lets you rotate, scale, skew, or translate an element.

## Examples

**This is an example below: css-api**

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

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

const Transform = () => {
  const containerStyle = {
    flexDirection: "column" as const,
    alignItems: "center",
    padding: "20px",
    backgroundColor: "#f5f5f5",
  } as const;

  const boxBaseStyle = {
    width: "120px",
    height: "120px",
    backgroundColor: "#2196F3",
    margin: "25px",
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
  } as const;

  const textStyle = {
    color: "white",
    fontSize: "16px",
    textAlign: "center" as const,
  } as const;

  const rotateStyle = {
    ...boxBaseStyle,
    transform: "rotate(45deg)",
    backgroundColor: "#4CAF50",
  } as const;

  const scaleStyle = {
    ...boxBaseStyle,
    transform: "scale(1.2)",
    backgroundColor: "#FF9800",
  } as const;

  const translateStyle = {
    ...boxBaseStyle,
    transform: "translate(50px, 0)",
    backgroundColor: "#9C27B0",
  } as const;

  const multipleStyle = {
    ...boxBaseStyle,
    transform: "rotate(45deg) scale(0.8) translate(50px, 0)",
    backgroundColor: "#E91E63",
  } as const;

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view style={containerStyle}>
        <view style={rotateStyle}>
          <text style={textStyle}>Rotate 45°</text>
        </view>

        <view style={scaleStyle}>
          <text style={textStyle}>Scale 1.2x</text>
        </view>

        <view style={translateStyle}>
          <text style={textStyle}>Move Right 50px</text>
        </view>

        <view style={multipleStyle}>
          <text style={textStyle}>Combined Effects</text>
        </view>
      </view>
    </scroll-view>
  );
};

root.render(<Transform />);

```

v0.11.0



## Syntax

```scss
/* Function values */
transform: rotate(0.5turn);
transform: rotateX(10deg);
transform: rotateY(10deg);
transform: translate(12px, 50%);
transform: translate3d(12px, 50%, 3em);
transform: translateX(2em);
transform: translateY(3px);
transform: translateZ(2px);
transform: scale(2, 0.5);
transform: scaleX(2);
transform: scaleY(0.5);

// equal to transform: translate(50px, 100px);
transform: matrix(1, 0, 0, 1, 50, 100);
// equal to transform: translateX(100px);
transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 100, 0, 0, 1);

/* Multiple function values */
transform: translateX(10px) rotate(10deg) translateY(5px);
transform: translate3d(10px, 0, 20px) rotateY(3deg);
```

The value of the `transform` can be one or more `<function>`, which are separated by spaces. For details, see [function standard syntax](#function-standard-syntax)

### function standard syntax

- **translate**

```
translate( <length> | <percentage> , <length> | <percentage>? )
```

- **translateX**

```
translateX( <length> | <percentage> )
```

- **translateY**

```
translateY( <length> | <percentage> )
```

- **translateZ**

```
translateZ( <length> )
```

:::info
When using translateZ, it is recommended to set `flatten={false}` on the parent node of the node, otherwise it may cause the `overflow:hidden` of the parent node to fail on Android.
At the same time, if translateZ does not take effect on Android, you can try to set other sibling nodes of the same parent node to `transform: translateZ(0)`.
:::

- **translate3d**

```
translate3d( <length> | <percentage> , <length> | <percentage> , <length> )
```

- **rotate**

```
rotate( [ <angle> | <zero> ] )
```

- **rotateZ**

```
rotateZ( [ <angle> | <zero> ] )
```

- **rotateX**

```
rotateX( [ <angle> | <zero> ] )
```

- **rotateY**

```
rotateY( [ <angle> | <zero> ] )
```

- **scale**

```
scale( <number> , <number>? )
```

- **scaleX**

```
scaleX( <number> )
```

- **scaleY**

```
scaleY( <number> )
```

- **skew**

```
skew( [ <angle> | <zero> ], [ <angle> | <zero> ] )
```

- **skewX**

```
skewX( [ <angle> | <zero> ] )
```

- **skewY**

```
skewY( [ <angle> | <zero> ] )
```

- **matrix**

```
matrix(a, b, c, d, tx, ty)
```

- **matrix3d**

```
matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
```

::: info

- `matrix(a, b, c, d, tx, ty)` is shorthand for `matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1)`.

- The `matrix3d()` function is specified with 16 arguments. These parameters are described in column-dominated order.
  - `a1`, `b1`, `c1`, `d1`
    define the first vector and are responsible for the X-axis scaling, rotation, and shear transformations;
  - `a2`, `b2`, `c2`, `d2`
    define the second vector and are responsible for the Y-axis scaling, rotation, and shear transformations;
  - `a3`, `b3`, `c3`, `d3`
    define the third vector and are responsible for the Z-axis scaling, rotation, and shear transformations;
  - `a4`, `b4`, `c4`, `d4`
    define the third vector, `a4`, `b4` and `c4` realize the translation transformation of x, y and z axes, and `d4` is generally set to 1, which is a value to keep the calculated weight stable.

:::

## Formal definition

| Initial value | empty value |
| Applies to | all elements |
| Inherited | no |
| Animatable | yes |


## Notes

:::info

- If you want 3D effect when transform rotateX and rotateY rotate, you need to cooperate with [perspective property](/next/api/css/properties/perspective.md).

- On iOS, if there is jaggedness in rotate, anti-aliasing can be turned on by adding the `allow-edge-antialiasing` attribute to the node.

```jsx
<view allow-edge-antialiasing={true}></view>
```

- `iOS` will penetrate other sibling nodes in the same layer when rendering `rotateX/rotateY`. If you do not want this penetration effect, wrap the node with a Wrapper View so that it is not in the same layer as its sibling nodes. Since an empty Wrapper View will be optimized and deleted by layout only, without generating an actual node, please add a default `transform` property value to the Wrapper View (e.g. `transform: translate(0,0)`) to prevent it from being layout only.

:::

:::info

- The transform property is order-dependent, and the order of translate, rotate, and scale will affect the final rendering effect.

- The table below shows whether Lynx considers the order of transform in various scenarios:

| Scenario                    | Consideration of Transform Order |
| --------------------------- | -------------------------------- |
| Static transform in Android | Yes                              |
| Static transform in iOS     | Yes                              |
| Transform in Android        | Yes                              |
| Transform in iOS            | Yes                              |

- _What is a static transform: It refers to the transform property that is rendered directly without animation in CSS._

:::

## Difference from W3C

- not support rotate3d, scale3d

## Compatibility

**Compatibility Table**

**Query:** `css.properties.transform`

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json) · [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/transform)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| transform | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| translate | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| translateX | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| translateY | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| translateZ | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| translate3d | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| rotate | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| rotateZ | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| rotateX | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| rotateY | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| scale | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| scaleX | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| scaleY | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| skew | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| skewX | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| skewY | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| matrix | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| matrix3d | Yes (1.0) | Unknown | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| rotate3d | No | Unknown | No | No | No | Yes |
| scale3d | No | Unknown | No | No | No | Yes |

**`transform`**

**Specifications:**

**`translate`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`translateX`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`translateY`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`translateZ`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`translate3d`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`rotate`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`rotateZ`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`rotateX`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`rotateY`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`scale`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`scaleX`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`scaleY`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`skew`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`skewX`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`skewY`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`matrix`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`matrix3d`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`rotate3d`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

**`scale3d`**

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/63-transform.json)

