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

# position

APISummary
## Introduction

The `position` CSS property sets how an element is positioned in a document. The [`top`](/next/api/css/properties/top.md), [`right`](/next/api/css/properties/right.md), [`bottom`](/next/api/css/properties/bottom.md), and [`left`](/next/api/css/properties/left.md) properties determine the final location of positioned elements.

## Types of positioning

- A positioned element is an element whose computed position value is either `relative`, `absolute`, `fixed`, or `sticky`.

- A relatively positioned element is an element whose computed position value is relative. The [`top`](/next/api/css/properties/top.md) and [`bottom`](/next/api/css/properties/bottom.md) properties specify the vertical offset from its normal position; the [`left`](/next/api/css/properties/left.md) and [`right`](/next/api/css/properties/right.md)properties specify the horizontal offset.

- An absolutely positioned element is an element whose computed position value is `absolute` or `fixed`. The `top`, `right`, `bottom`, and `left` properties specify offsets from the edges of the element's containing block. (The containing block is the ancestor relative to which the element is positioned.) If the element has margins, they are added to the offset. The element establishes a new block formatting context (BFC) for its contents.

- A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.

Most of the time, absolutely positioned elements that have [`height`](/next/api/css/properties/height.md) and [`width`](/next/api/css/properties/width.md) set to auto are sized so as to fit their contents. However, absolutely positioned elements can be made to fill the available vertical space by specifying both `top` and `bottom` and leaving `height` unspecified (that is, `auto`). They can likewise be made to fill the available horizontal space by specifying both `left` and `right` and leaving width as `auto`.

Except for the case just described (of absolutely positioned elements filling the available space):

If both `top` and `bottom` are specified (technically, not auto), `top` wins.
If both `left` and `right` are specified, `left` wins when direction is `ltr` (English, horizontal Japanese, etc.) and `right` wins when `direction` is `rtl` (Persian, Arabic, Hebrew, etc.).

## Examples

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

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

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

const Position = () => {
  const boxStyles = {
    fixed1: {
      position: "fixed" as const,
      top: "5px",
      left: "5px",
      width: "50px",
      height: "50px",
      backgroundColor: "red",
    },
    absolute1: {
      position: "absolute" as const,
      top: "0px",
      left: "50px",
      width: "50px",
      height: "50px",
      backgroundColor: "brown",
    },
    fixed2: {
      position: "fixed" as const,
      top: "5px",
      left: "105px",
      width: "50px",
      height: "50px",
      backgroundColor: "pink",
    },
    absolute2: {
      position: "absolute" as const,
      right: "0px",
      width: "50px",
      height: "50px",
      backgroundColor: "coral",
    },
    fixed3: {
      position: "fixed" as const,
      left: "5px",
      top: "55px",
      width: "50px",
      height: "50px",
      backgroundColor: "Chocolate",
    },
    absolute3: {
      position: "absolute" as const,
      left: "100px",
      top: "50px",
      width: "50px",
      height: "50px",
      backgroundColor: "DarkOrange",
    },
    absolute4: {
      position: "absolute" as const,
      top: "50px",
      left: "50px",
      width: "50px",
      height: "50px",
      backgroundColor: "yellow",
    },
    absolute5: {
      position: "absolute" as const,
      left: "150px",
      top: "50px",
      width: "50px",
      height: "50px",
      backgroundColor: "GoldenRod",
    },
    absolute6: {
      position: "absolute" as const,
      left: "0px",
      top: "100px",
      width: "50px",
      height: "50px",
      backgroundColor: "GreenYellow",
    },
    absolute7: {
      position: "absolute" as const,
      left: "50px",
      top: "100px",
      width: "50px",
      height: "50px",
      backgroundColor: "LightBlue",
    },
    absolute8: {
      position: "absolute" as const,
      left: "150px",
      top: "100px",
      width: "50px",
      height: "50px",
      backgroundColor: "DodgerBlue",
    },
    absolute9: {
      position: "absolute" as const,
      left: "0px",
      top: "150px",
      width: "50px",
      height: "50px",
      backgroundColor: "DarkTurquoise",
    },
    fixed4: {
      position: "fixed" as const,
      left: "55px",
      top: "155px",
      width: "50px",
      height: "50px",
      backgroundColor: "DarkSlateBlue",
    },
    fixed5: {
      position: "fixed" as const,
      left: "105px",
      top: "155px",
      width: "50px",
      height: "50px",
      backgroundColor: "DarkSlateGrey",
    },
    absolute10: {
      position: "absolute" as const,
      bottom: "50px",
      right: "50px",
      width: "50px",
      height: "50px",
      backgroundColor: "green",
    },
    fixed6: {
      position: "fixed" as const,
      top: "155px",
      left: "155px",
      width: "50px",
      height: "50px",
      backgroundColor: "blue",
    },
    leadIn: {
      height: "72px",
      justifyContent: "center" as const,
      alignItems: "center" as const,
      backgroundColor: "#f4f4f5",
    },
    stickyHeader: {
      position: "sticky" as const,
      top: "0px",
      zIndex: 1,
      width: "750rpx",
      height: "44px",
      justifyContent: "center" as const,
      alignItems: "center" as const,
      backgroundColor: "#111827",
    },
    stickyText: {
      color: "#ffffff",
      fontSize: "14px",
    },
    tail: {
      height: "260px",
      justifyContent: "center" as const,
      alignItems: "center" as const,
      backgroundColor: "#f4f4f5",
    },
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view style={boxStyles.leadIn}>
        <text>Scroll to see position: sticky</text>
      </view>
      <view style={boxStyles.stickyHeader}>
        <text style={boxStyles.stickyText}>position: sticky; top: 0</text>
      </view>
      <view className="fixed_area">
        <view className="container">
          <view style={boxStyles.fixed1}></view>
          <view style={boxStyles.absolute1}></view>
          <view style={boxStyles.fixed2}></view>
          <view style={boxStyles.absolute2}></view>
          <view style={boxStyles.fixed3}></view>
          <view style={boxStyles.absolute3}></view>
          <view style={boxStyles.absolute4}></view>
          <view style={boxStyles.absolute5}></view>
          <view style={boxStyles.absolute6}></view>
          <view style={boxStyles.absolute7}></view>
          <view style={boxStyles.absolute8}></view>
          <view style={boxStyles.absolute9}></view>
          <view style={boxStyles.fixed4}></view>
          <view style={boxStyles.fixed5}></view>
          <view style={boxStyles.absolute10}></view>
          <view style={boxStyles.fixed6}></view>
        </view>
      </view>
      <view style={boxStyles.tail}>
        <text>The sticky bar stays at the top while scrolling.</text>
      </view>
    </scroll-view>
  );
};

root.render(<Position />);

```

v0.11.0



## Syntax

```css
position: relative;
position: fixed;
position: absolute;
position: sticky;
```

### Values

#### `relative`

**default value**. The element is positioned according to the normal flow of the document, and then offset relative to itself based on the values of `top`, `right`, `bottom`, and `left`. The offset does not affect the position of any other elements.

#### `absolute`

The element is removed from the normal document flow, and no space is created for the element in the page layout. It is positioned relative to the containing block of its parent element. Its final position is determined by the values of `top`, `right`, `bottom`, and `left`.

#### `fixed`

The element is will be treated as a direct child of root node with the property `position` as `absolute`. Its final position is determined by the values of top, right, bottom, and left.

#### `sticky`

The element is positioned according to the normal flow of the document, then offset relative to its nearest scrolling container and containing block, based on the values of [`top`](/next/api/css/properties/top.md), [`right`](/next/api/css/properties/right.md), [`bottom`](/next/api/css/properties/bottom.md) and [`left`](/next/api/css/properties/left.md). The offset does not affect the position of any other element.

Before 3.9, `sticky` only applied to direct children of a `scroll-view`.

## Formal definition

| Initial value | `relative` |
| Applies to | all elements |
| Inherited | no |
| Animatable | no |


## Formal syntax

```
position: relative | absolute | fixed | sticky
```

## Differences from the Web

[mdn:position](https://developer.mozilla.org/en-US/docs/Web/CSS/position)

1. Lynx does not support `static` and default value is `relative`.

## Compatibility

**Compatibility Table**

**Query:** `css.properties.position`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| position | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| relative | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| absolute | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| fixed | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| sticky | Yes (1.4) | Yes (3.4) | Yes (1.4) | Yes (1.4) | Yes (1.4) | Yes |
| static | No | No | No | No | No | Yes |

**`position`**

**Specifications:**

**`relative`**

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

**`absolute`**

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

**`fixed`**

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

**`sticky`**

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

**`static`**

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


## FAQ

1. If using [`z-index`](/next/api/css/properties/z-index.md) in `position: absolute` element, please set `z-index: 0` in parent element at the same time.
