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

# flex

APISummary
## Introduction

The `flex` CSS shorthand property sets how a flex item will grow or shrink to fit the space available in its flex container. This property is a shorthand for the following CSS properties: [`flex-grow`](/next/api/css/properties/flex-grow.md), [`flex-shrink`](/next/api/css/properties/flex-shrink.md), [`flex-basis`](/next/api/css/properties/flex-basis.md).

## Examples

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

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

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

const Flex = () => {
  const firstBoxStyle = {
    flex: "1",
    backgroundColor: "rgba(255,0,200,0.2)",
  };

  const secondBoxStyle = {
    flex: "1 30px",
    marginLeft: "5px",
    backgroundColor: "rgba(0,0,255,0.2)",
  };

  const thirdBoxStyle = {
    flex: "2 1 auto",
    marginLeft: "5px",
    backgroundColor: "rgba(0,0,255,0.2)",
  };

  return (
    <view className="container">
      <view className="height" style={firstBoxStyle}>
        <text>flex:1;</text>
      </view>
      <view className="height" style={secondBoxStyle}>
        <text>flex:1 30px;</text>
      </view>
      <view className="height" style={thirdBoxStyle}>
        <text>flex:2 1 auto;</text>
      </view>
    </view>
  );
};

root.render(<Flex />);

```

v0.11.0



## Syntax

```css
flex: none;
flex: auto;

/* One value, unitless number: flex-grow
flex-basis is then equal to 0% (0 before Lynx 3.9). */
flex: 2;

/* One value, width/height: flex-basis */
flex: 10em;
flex: 30%;

/* Two values: flex-grow | flex-basis */
flex: 1 30px;

/* Two values: flex-grow | flex-shrink */
flex: 2 2;

/* Three values: flex-grow | flex-shrink | flex-basis */
flex: 2 2 10%;
```

The `flex` property may be specified using one, two, or three values.

- **One-value syntax**:
  - A unitless [`<number>`](/next/api/css/data-type/number.md), which will be used as the value of [`<flex-grow>`](/next/api/css/properties/flex-grow.md), then the shorthand expands to `flex: <flex-grow> 1 0%`. 3.9 Before 3.9 it expanded to a unitless `0`; see [Flex basis 0 vs 0%](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/flex-basis#flex_basis_0_vs_0) for the difference.
  - A valid [`<length>`](/next/api/css/data-type/length.md) or [`<percentage>`](/next/api/css/data-type/percentage.md) or key word `auto`, it will be used as the value of [`<flex-basis>`](/next/api/css/properties/flex-basis.md), then the shorthand expands to `flex: 1 1 <flex-basis>`.

- **Two-value syntax**:
  - The first value must be a valid value for [`<flex-grow>`](/next/api/css/properties/flex-grow.md).
  - The second value must be one of:
    - A unitless [`<number>`](/next/api/css/data-type/number.md), which will be used as the value of [`<flex-shrink>`](/next/api/css/properties/flex-shrink.md), then the shorthand expands to `flex: <flex-grow> <flex-shrink> 0%`. 3.9 Before 3.9 this was a unitless `0`.
    - A valid [`<length>`](/next/api/css/data-type/length.md) or [`<percentage>`](/next/api/css/data-type/percentage.md) or key word `auto`, it will be used as the value of [`<flex-basis>`](/next/api/css/properties/flex-basis.md), then the shorthand expands to `flex: <flex-grow> 1 <flex-basis>`.

- Three-value syntax: the values must be in the following order:
  - A unitless [`<number>`](/next/api/css/data-type/number.md), which will be used as the value of [`<flex-grow>`](/next/api/css/properties/flex-grow.md).
  - A unitless [`<number>`](/next/api/css/data-type/number.md), which will be used as the value of [`<flex-shrink>`](/next/api/css/properties/flex-shrink.md).
  - A valid [`<length>`](/next/api/css/data-type/length.md) or [`<percentage>`](/next/api/css/data-type/percentage.md) or key word `auto`, it will be used as the value of [`<flex-basis>`](/next/api/css/properties/flex-basis.md).

### Values

- `0 1 auto`

  **Default value**. The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container.

- `auto`

  The item is sized according to its width and height properties, but grows to absorb any extra free space in the flex container, and shrinks to its minimum size to fit the container. This is equivalent to setting "`flex: 1 1 auto`".

- `none`

  The item is sized according to its width and height properties. It is fully inflexible: it neither shrinks nor grows in relation to the flex container. This is equivalent to setting "`flex: 0 0 auto`".

- `<flex-grow>`

  Defines the [`flex-grow`](/next/api/css/properties/flex-grow.md) of the flex item. Negative values are considered invalid. Defaults to 1 when omitted.

- `<flex-shrink>`

  Defines the [`flex-shrink`](/next/api/css/properties/flex-shrink.md) of the flex item. Negative values are considered invalid. Defaults to 1 when omitted.

- `<flex-basis>`

  Defines the [`flex-basis`](/next/api/css/properties/flex-basis.md) of the flex item. A preferred size of 0 must have a unit to avoid being interpreted as a flexibility. Defaults to `auto` when omitted. (initial is auto)

## Formal definition

| Initial value | as each of the properties of the shorthand: 
- `flex-grow: 0`
- `flex-shrink: 1`
- `flex-basis: auto` |
| Applies to | flex items |
| Inherited | no |
| Animatable |  |


## Formal syntax

```
flex =
  none                                                |
  [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]

<flex-grow> =
  <number [0,∞]>

<flex-shrink> =
  <number [0,∞]>

<flex-basis> = <'width'>

<width> =
  auto                                      |
  <length-percentage [0,∞]>                 |
  max-content                               |
  fit-content( <length-percentage [0,∞]> )

<length-percentage> =
  <length>      |
  <percentage>
```

## Compatibility

**Compatibility Table**

**Query:** `css.properties.flex`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| flex | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| none | Yes (2.12) | Yes (3.4) | Yes (2.12) | Yes (2.12) | Yes (2.12) | Yes |

**`flex`**

**Specifications:**

**`none`**

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

