> 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

APISummary
## Introduction

The `background` shorthand CSS property sets all background style properties at once, such as [`background-clip`](/next/api/css/properties/background-clip.md),[`background-color`](/next/api/css/properties/background-color.md),[`background-image`](/next/api/css/properties/background-image.md),[`background-origin`](/next/api/css/properties/background-origin.md),[`background-position`](/next/api/css/properties/background-position.md),[`background-repeat`](/next/api/css/properties/background-repeat.md),[`background-size`](/next/api/css/properties/background-size.md).

## Examples

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

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

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

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

  const container1Style = {
    backgroundOrigin: "content-box" as const,
    backgroundPosition: "left top" as const,
    backgroundRepeat: "no-repeat" as const,
  };

  const container2Style = {
    backgroundOrigin: "padding-box" as const,
    backgroundPosition: "50% 50%",
    backgroundRepeat: "repeat-x" as const,
  };

  const container3Style = {
    backgroundOrigin: "border-box" as const,
    backgroundPosition: "30px 40px",
    backgroundRepeat: "repeat" as const,
  };

  const container4Style = {
    backgroundOrigin: "content-box,border-box" as const,
    backgroundPosition: "50% 40px, right bottom",
    backgroundRepeat: "repeat-y,repeat-x" as const,
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="fixed_area" style={fixedAreaStyle}>
        <view className="container image1" style={container1Style}></view>
        <view className="container image1" style={container2Style}></view>
        <view className="container image1" style={container3Style}></view>
        <view className="container image2" style={container4Style}></view>
      </view>
    </scroll-view>
  );
};

root.render(<Background />);

```

v0.11.0



## Syntax

```css
/* Using a <background-color> */
background: green;

/* Using a <bg-image> and <repeat-style> */
background: url('test.jpg') repeat-y;

/* Using a <box> and <background-color> */
background: border-box red;

/* A single image, centered and scaled */
background: no-repeat center / 80% url('../img/image.png');
```

The background property is specified as one or more background layers, separated by commas.

The syntax of each layer is as follows:

- [`<bg-image>`](#bg-image)
- [`<position>`](#position)
- [`<bg-size>`](#bg-size)
- [`<repeat-style>`](#repeat-style)
- The `<bg-size>` value may only be included immediately after `<position>`, separated with the '/' character, like this: `"center/80%"`.
- The `<box>` value may be included zero, one, or two times. If included once, it sets both [`background-origin`](/next/api/css/properties/background-origin.md) and [`background-clip`](/next/api/css/properties/background-clip.md). If it is included twice, the first occurrence sets [`background-origin`](/next/api/css/properties/background-origin.md), and the second sets [`background-clip`](/next/api/css/properties/background-clip.md).

> **The [`background-color`](/next/api/css/properties/background-color.md) value may only be included in the last layer specified.**

### Values

#### `<box>` \{#box}

See [`background-clip`](/next/api/css/properties/background-clip.md) and [`background-origin`](/next/api/css/properties/background-origin.md)

#### `<background-color>` \{#background-color}

See [`background-color`](/next/api/css/properties/background-color.md)

#### `<bg-image>` \{#bg-image}

See [`background-image`](/next/api/css/properties/background-image.md)

#### `<position>` \{#position}

See [`background-position`](/next/api/css/properties/background-position.md)

#### `<repeat-style>` \{#repeat-style}

See [`background-repeat`](/next/api/css/properties/background-repeat.md)

#### `<bg-size>` \{#bg-size}

See [`background-size`](/next/api/css/properties/background-size.md)

## Notes

- The background-color must be written in the last image, otherwise the parser will consider it an invalid background.
  For example: `background: red url('./a.png'), url('./b.png);'` will be ignored as an error.
  The correct way to write it should be: `background: url('./a.png'),red url('./b.png);`

## Formal definition

| Initial value | background-image: none
background-position: 0% 0%
background-size: auto auto
background-repeat: repeat
background-origin: padding-box
background-clip: border-box
background-color: transparent |
| Applies to | all elements |
| Inherited | no |
| Animatable | no |


## Formal Syntax

```
[ <bg-layer> , ]* <final-bg-layer>

where

<bg-layer> = <bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <box> || <box>
<final-bg-layer> = <'background-color'> || <bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box> || <box>

where

<bg-image> = none | <image>
<bg-position> = [ [ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ] ]
<bg-size> = [ <length-percentage> | auto ]{1,2} | cover | contain
<repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1, 2}
<box> = border-box | padding-box | content-box

where

<image> = <url> | <gradient>
<length-percentage> = <length> | <percentage>

where

<gradient> = <linear-gradient> | <radial-gradient>

```

## Differences from the Web

- `<bg-layer>` does not support the [`<attachment>`](https://developer.mozilla.org/zh-CN/docs/Web/CSS/background#attachment)
- `<image>` only support `<url>` and `<gradient>`
  > \_These properties are also supported in web such as `<image-set>`、`<element()>`、`<paint()>`、`<cross-fade()>` \_

- `<gradient>` only support `<linear-gradient>` and `<radial-gradient>`
  > _These properties are also supported in web such as `<repeating-linear-gradient()>`,`<radial-gradient()>`,`<repeating-radial-gradient()>`,`<conic-gradient()>`_

## Compatibility

**Compatibility Table**

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

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

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

**`background`**

**Specifications:**

