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

# background-size

APISummary
## Introduction

The `background-size` CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space.

## Examples

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

**Entry:** `src/background-size`
**Bundle:** `dist/background-size.lynx.bundle`

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

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

  const containerStyles = {
    style1: {
      backgroundOrigin: "content-box" as const,
      backgroundPosition: "left top" as const,
      backgroundRepeat: "no-repeat" as const,
      backgroundSize: "50%",
    },
    style2: {
      backgroundOrigin: "padding-box" as const,
      backgroundPosition: "50% 50%",
      backgroundRepeat: "repeat-x" as const,
      backgroundSize: "40px, 30px",
    },
    style3: {
      backgroundOrigin: "border-box" as const,
      backgroundPosition: "50% 50%",
      backgroundRepeat: "repeat" as const,
      backgroundSize: "cover" as const,
    },
    style4: {
      backgroundOrigin: "content-box,border-box" as const,
      backgroundPosition: "top left, right bottom",
      backgroundRepeat: "repeat-y,repeat-x" as const,
      backgroundSize: "50% 50%, contain",
    },
    style5: {
      backgroundOrigin: "content-box" as const,
      backgroundPosition: "left top" as const,
      backgroundRepeat: "no-repeat" as const,
      backgroundSize: "auto 200%",
    },
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="fixed_area" style={fixedAreaStyle}>
        <view className="container image1" style={containerStyles.style1}></view>
        <view className="container image1" style={containerStyles.style2}></view>
        <view className="container image1" style={containerStyles.style3}></view>
        <view className="container image2" style={containerStyles.style4}></view>
        <view className="container image1" style={containerStyles.style5}></view>
      </view>
    </scroll-view>
  );
};

root.render(<BackgroundSize />);

```

v0.11.0



## Syntax

```css
background-size: contain;

background-size: 50%;
background-size: 3em;

background-size: auto 1em;
background-size: 50% 25%;
```

### Values

- `cover` 

  Scales the image as large as possible within its container without cropping or stretching the image. If the container is larger than the image, this will result in image tiling, unless the [`background-repeat`](/next/api/css/properties/background-repeat.md) property is set to `no-repeat`.

- `contain` 

  Scales the image (while preserving its ratio) to the smallest possible size to fill the container (that is: both its height and width completely cover the container), leaving no empty space. If the proportions of the background differ from the element, the image is cropped either vertically or horizontally.

- Default value **auto** 

  Scales the background image in the corresponding direction such that its intrinsic proportions are maintained.

- [`<length>`](/next/api/css/data-type/length.md) 

  Stretches the image in the corresponding dimension to the specified length. Negative values are not allowed.

- [`<percentage>`](/next/api/css/data-type/percentage.md) 

  Stretches the image in the corresponding dimension to the specified percentage of the background positioning area. The background positioning area is determined by the value of [`background-origin`](/next/api/css/properties/background-origin.md) (by default, the padding box).

### Size Calculation

- If both components of `background-size` are specified and are not `auto`: 

  The background image is rendered at the specified size.

- `contain` or `cover`: 

  While preserving its intrinsic proportions, the image is rendered at the largest size contained within, or covering, the background positioning area. If the image has no intrinsic proportions, then it's rendered at the size of the background positioning area.

- If the background-size has one `auto` component and one `non-auto` component: 

  The image stretched to the specified dimension. The unspecified dimension is computed using the specified dimension and the intrinsic proportions.

## Notes

Do not use `auto` with `<gradient>`. It may cause some rendering issue in old version SDK.

## Formal definition

| Initial value | auto auto |
| Applies to | all elements |
| Inherited | no |
| Animatable | no |


## Formal Syntax

```
<bg-size> = (<length-percentage> | auto){1,2} | cover | contain
```

## Compatibility

**Compatibility Table**

**Query:** `css.properties.background-size`

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

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

**`background-size`**

**Specifications:**

