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

# aspect-ratio

APISummary
## Introduction

The `aspect-ratio` CSS property sets a preferred aspect-ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.

## Examples

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

**Entry:** `src/aspect-ratio`
**Bundle:** `dist/aspect-ratio.lynx.bundle`

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

const AspectRatio = () => {
  const textStyle = {
    width: "50px",
    aspectRatio: "1/4",
    backgroundColor: "red",
  };

  const fixedAreaStyle = {
    width: "100%",
    height: "100%",
    flexDirection: "column" as const,
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="fixed_area" style={fixedAreaStyle}>
        <text style={textStyle}>test</text>
      </view>
    </scroll-view>
  );
};

root.render(<AspectRatio />);

```

v0.11.0



## Syntax

```css
aspect-ratio: 1 / 1;
aspect-ratio: 16 / 9;
aspect-ratio: 0.5;
```

### Values

#### `<ratio>`

The box's preferred aspect-ratio is the ratio of `width` to `height`. If the height and preceding slash are omitted, height defaults to 1. Size calculations involving aspect-ratio use the dimensions of the box specified by [`box-sizing`](/next/api/css/properties/box-sizing.md).

:::info
The `<ratio>` CSS data type represents a ratio between two numbers. It consists of:

- A positive [`<number>`](/next/api/css/data-type/number.md) value
- Followed by a forward slash ('/', Unicode U+002F SOLIDUS)
- Followed by a second positive `<number>` value
- Alternatively, a single positive `<number>` is allowed as a value
  :::

## Formal definition

| Initial value | has no preferred `aspect ratio` |
| Applies to | all elements |
| Inherited | no |
| Animatable |  |


## Formal syntax

```css
aspect-ratio = <number [0,∞]> [ / <number [0,∞]> ]
```

## Differences from the Web

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

1. `auto` is not supported, one has no preferred `aspect-ratio` by default.

## Compatibility

**Compatibility Table**

**Query:** `css.properties.aspect-ratio`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| aspect-ratio | Yes (1.2) | Yes (3.4) | Yes (1.2) | Yes (1.2) | Yes (1.2) | Yes |
| auto | No | No | No | No | No | Yes |

**`aspect-ratio`**

**Specifications:**

**`auto`**

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

