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

# linear-weight

APISummary
## Introduction

Child element's weight in [linear](/next/guide/ui/layout/linear-layout.md).
The parent container automatically allocates the length of the corresponding side of the child elements according to the weight value ratio of all child elements and the size of the remaining space.

## Examples

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

**Entry:** `src/linear-weight`
**Bundle:** `dist/linear-weight.lynx.bundle`

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

const LinearWeight = () => {
  const [linearOrientation, setLinearOrientation] = useState(false);
  const containerStyle = {
    linearOrientation: linearOrientation ? "horizontal" : "vertical" as "horizontal" | "vertical",
  };
  const buttonStyle = {
    width: "20%",
    height: "50px",
    backgroundColor: "red" as const,
  };
  const text1Style = {
    fontSize: "40rpx" as const,
    marginRight: "12rpx",
    fontWeight: "900" as const,
    color: "linear-gradient(120deg ,#0095ff 30% ,#42d392 100%)" as const,
  };
  const text2Style = {
    fontSize: "50rpx" as const,
    alignSelf: "center" as const,
    fontWeight: "900" as const,
    color: "linear-gradient(120deg,#0095ff 30%,#42d392 100%)" as const,
  };
  const Container1View1Style = {
    width: "30px",
    height: "30px",
    linearWeight: 0.5,
    backgroundColor: "red" as const,
  };
  const Container1View2Style = {
    width: "30px",
    height: "30px",
    linearWeight: 2,
    backgroundColor: "yellow" as const,
  };
  const Container1View3Style = {
    width: "30px",
    height: "30px",
    linearWeight: 0.5,
    backgroundColor: "blue" as const,
  };

  const Container2View1Style = {
    width: "30px",
    height: "30px",
    linearWeight: 1,
    backgroundColor: "red" as const,
  };
  const Container2View2Style = {
    width: "30px",
    height: "30px",
    linearWeight: 1,
    backgroundColor: "yellow" as const,
  };
  const Container2View3Style = {
    width: "30px",
    height: "30px",
    linearWeight: 1,
    backgroundColor: "blue" as const,
  };

  const Container3View1Style = {
    width: "30px",
    height: "30px",
    linearWeight: 0.5,
    backgroundColor: "red" as const,
  };
  const Container3View2Style = {
    width: "30px",
    height: "30px",
    linearWeight: 0.5,
    backgroundColor: "yellow" as const,
  };
  const Container3View3Style = {
    width: "30px",
    height: "30px",
    linearWeight: 2,
    backgroundColor: "blue" as const,
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view style={buttonStyle} bindtap={() => setLinearOrientation(!linearOrientation)}></view>
      <text style={text1Style}>Click above red button to switch linear-direction</text>
      <text style={text2Style}>Current: "{linearOrientation ? "row" : "column"}"</text>
      <text className="title">linear-weight: 0.5 2 0.5</text>
      <view className="linear_container" style={containerStyle}>
        <view style={Container1View1Style} />
        <view style={Container1View2Style} />
        <view style={Container1View3Style} />
      </view>

      <text className="title">linear-weight: 1 1 1</text>
      <view className="linear_container" style={containerStyle}>
        <view style={Container2View1Style} />
        <view style={Container2View2Style} />
        <view style={Container2View3Style} />
      </view>

      <text className="title">linear-weight: 0.5 0.5 2</text>
      <view className="linear_container" style={containerStyle}>
        <view style={Container3View1Style} />
        <view style={Container3View2Style} />
        <view style={Container3View3Style} />
      </view>
    </scroll-view>
  );
};

root.render(<LinearWeight />);

```

v0.11.0



## Syntax

```css
linear-weight: 3;
linear-weight: 5;
```

### Values

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

  Negative values are invalid. **Default value is 0**. When the linear-weight of a sub-element in linear layout is 0, the layout of the child element will not be affected by the linear-weight.

## Formal definition

| Initial value | `0` |
| Applies to | linear items |
| Inherited | no |
| Animatable |  |


## Formal syntax

```
linear-weight = <number>
```

## Differences from the Web

- No such style in Web.

## Compatibility

**Compatibility Table**

**Query:** `css.properties.linear-weight`

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

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

**`linear-weight`**

Child element's weight in linear layout.

**Specifications:**


## FAQ

- It is not supported to use a fixed value and weight at the same time. If there is a `weight`, the fixed value is automatically ignored (performance first).
