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

# `<page>`

`<page>` 是页面的根节点，一个页面上只能有一个 `<page>`。你也可以不在页面最外层显式写 `<page>`，前端框架会默认生成根节点。

## 使用指南

### 选择不写 `<page>`

默认情况下，你无需手动添加 `<page>`，前端框架会生成根节点。

在这种情况下，虽然无法显式设置 `style` 和 `class` 等属性，但是通过 [`page`](/next/zh/api/css/selectors.md#通过-page-来选择根节点) 和 [`:root`](/next/zh/api/css/selectors.md#root-selector) 选择器，你仍然可以很方便的给根节点添加样式，也可通过 [`SelectorQuery:selectRoot()`](/next/zh/api/lynx-api/selector-query/selector-query-select-root.md) 来选择根节点。

```css
/* 使用 page 选择器添加样式 */
page {
  background-color: white;
}

/* 或者使用 :root 选择器添加样式 */
:root {
  background-color: white;
}
```

**下面是一个示例: page**

**Entry:** `src/no_page_tag/`
**Bundle:** `dist/no_page_tag.lynx.bundle` | Web: `dist/no_page_tag.web.bundle`

```scss {1-3,5-8}
:root {
  background: linear-gradient(120deg, rgb(255, 53, 26), rgb(0, 235, 235));
}

page {
  border: 10px solid black;
  border-radius: 20px;
}

.title {
  font-size: 20px;
  font-weight: bold;
}

```

v0.7.0



### 显式使用 `<page>`

如果你想更灵活的给根节点添加样式或者绑定事件，可以选择在最外层添加 `<page>`。其用法跟 `<view>` 一致，可以使用 `<view>` 上除了[宽、高、位置](#不能直接修改大小)外的其他所有样式和属性。

```jsx {3,7}
const App = () => {
  return (
    <page className="body" bindtap={handlePageClick}>
      <view style={{ width: '100%', height: '100%' }}>
        <text className="title">Page Example</text>
      </view>
    </page>
  );
};
```

跟 `<view>` 类似，可以添加 `style`、`class` 以及绑定事件等，请注意，你只能写一个 `<page>`。

**下面是一个示例: page**

**Entry:** `src/with_page_tag/`
**Bundle:** `dist/no_page_tag.lynx.bundle` | Web: `dist/no_page_tag.web.bundle`

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

const App = () => {
  const [showPopup, setShowPopup] = useState(false);

  const handlePageClick = () => {
    setShowPopup(prev => !prev);
  };

  return (
    <page className="container" bindtap={handlePageClick}>
      <view
        style={{
          width: "100%",
          height: "100%",
          alignItems: "center",
          justifyContent: "center",
        }}
      >
        <text className="title">Use Page Element Example, Click it</text>
      </view>
      {showPopup && (
        <view className="popup">
          <text className="popup-text">Click Response</text>
        </view>
      )}
    </page>
  );
};

root.render(<App />);

if (import.meta.webpackHot) {
  import.meta.webpackHot.accept();
}

```

v0.7.0



### 不能直接修改大小

`<page>` 的大小约束是由[客户端](/next/zh/guide/embed-lynx-to-native.md#Constraining-LynxView)上其所在的外层视图指定，你无法直接通过 `style` 或者 `class` 修改其 `width`、`height`、`left`、`top` 样式。这样设计的好处是可以让 Lynx 页面嵌入到客户端页面中，从而更好自适应客户端视图的排版流程。
