> 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.

# direction

APISummary
## 介绍

`direction` 属性设置文字、元件的布局方向。例如 `ltr` 表示从左向右 (类似中文等)，`rtl` 表示从右向左 (类似阿拉伯语等)。

## 使用示例

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

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

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

const Direction = () => {
  const [rtl, setRtl] = useState(false);

  const containerStyle = {
    direction: rtl ? "rtl" : "ltr" as "rtl" | "ltr",
  };

  return (
    <>
      <view className="con" bindtap={() => setRtl(!rtl)} style={containerStyle}>
        <text className="intro">rtl|ltr</text>
      </view>
      <text>current: {rtl ? "rtl" : "ltr"}</text>
    </>
  );
};

root.render(<Direction />);

```

v0.11.0



## 语法

```css
direction: normal;
direction: ltr;
direction: rtl;
direction: lynx-rtl;
```

### 取值

- `normal`

  **默认值**。与 `ltr` 表现一致，是兼容产物。

- `ltr`

  文字从左向右排列，水平方向的逻辑属性 `start` 映射到 `left`，`end` 映射到 `right`。

- `rtl`

  文字从右向左排列，水平方向的逻辑属性 `start` 映射到 `right`，`end` 映射到 `left`。

- `lynx-rtl` deprecated

  **lynx 兼容属性**，文字从右向左排列，水平方向的属性 `left` 映射到 `right`，`right` 映射到 `left`。

## 形式定义

| 初始值 | normal |
| 适用元素 | 所有元件 |
| 是否支持继承 | 是 |
| 是否支持动画 |  |


## 形式语法

```
direction = normal | ltr | rtl
```

## 与 Web 的区别

- 引入 `normal`、`lynx-rtl` 等兼容属性，用来提高 lynx 易用性。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.direction`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| direction | Yes (2.0) | Yes (3.4) | Yes (2.0) | Yes (2.0) | Yes (2.0) | Partial |
| lynx-rtl | Yes (2.0) | Yes (3.4) | Yes (2.0) | Yes (2.0) | Yes (2.0) | Yes |

**`direction`**

**Specifications:**

- **Web — Supported (version unknown):** Partial support; direction:rtl is as powerful as direction:lynx-rtl

**`lynx-rtl`**

<code>lynx-rtl</code>

