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

# top

APISummary
## Introduction

The `top` CSS property participates in specifying the vertical position. For more information, please refer to property [`position`](/next/api/css/properties/position.md).

The effect of `top` depends on how the element is positioned (i.e., the value of the position property):

- When position is set to `absolute` or `fixed`, the `top` property specifies the distance between the element's outer margin of top edge and the inner border of the top edge of its containing block.

- When `position` is set to `relative`, the `top` property specifies the distance the element's top edge is moved below its normal position.

When both `top` and `bottom` are specified, position is set to `absolute` or `fixed`, and `height` is unspecified (either `auto` or 100%) both the `top` and `bottom` distances are respected. In all other situations, if `height` is constrained in any way or `position` is set to `relative`, the top property takes precedence and the `bottom` property is ignored.

## Examples

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

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

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

const Top = () => {
  const containerStyle = {
    width: "210px",
    height: "210px",
    border: "5px",
    borderColor: "black",
  };

  const firstBoxStyle = {
    position: "absolute" as const,
    top: "80px",
    width: "50px",
    height: "50px",
    backgroundColor: "red",
  };

  const secondBoxStyle = {
    position: "fixed" as const,
    top: "155px",
    width: "50px",
    height: "50px",
    backgroundColor: "green",
  };

  const thirdBoxStyle = {
    position: "relative" as const,
    top: "155px",
    width: "50px",
    height: "50px",
    backgroundColor: "yellow",
  };

  const fourthBoxStyle = {
    width: "50px",
    height: "50px",
    backgroundColor: "blue",
  };

  return (
    <view style={containerStyle}>
      <view style={firstBoxStyle}></view>
      <view style={secondBoxStyle}></view>
      <view style={thirdBoxStyle}></view>
      <view style={fourthBoxStyle}></view>
    </view>
  );
};

root.render(<Top />);

```

v0.11.0



## Syntax

```css
/* <length> values */
top: 3px;
top: 2rpx;
top: 2.4em;
top: 3rem;

top: 10%;

/* Keyword value */
top: auto;

/* calc */
top: calc(1px + 1px);
```

### Values

#### `auto`

**Default value**.

#### `<length>`

A negative, null, or positive [`<length>`](/next/api/css/data-type/length.md) that represents:

- for absolutely positioned elements, the distance to the top edge of the containing block.

- for relatively positioned elements, the distance that the element is moved below its normal position.

#### `<percentage>`

Defines the height as a percentage of the [containing block](https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block)'s height.

## Formal definition

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


## See also

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

## Compatibility

**Compatibility Table**

**Query:** `css.properties.top`

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

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

**`top`**

participates in setting the vertical position of a positioned element. It has no effect on non-positioned elements.

**Specifications:**

