# Flex

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/flex
- **Markdown:** https://refast.fastapicloud.dev/docs/components/flex.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/layout/flex.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Generic flexbox container with full directional control. For most cases prefer
`Row` (horizontal) or `Column` (vertical) directly — `Flex` is useful when you
need to switch direction dynamically.

```python
from refast.components import Flex

Flex(
    direction="row",
    justify="between",
    align="center",
    gap=4,
    wrap=True,
    children=[...],
)
```

## Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `list \| Component \| None` | `None` | Child components |
| `direction` | `"row" \| "column" \| "row-reverse" \| "column-reverse"` | `"row"` | flex-direction |
| `justify` | `"start" \| "end" \| "center" \| "between" \| "around" \| "evenly"` | `"start"` | justify-content |
| `align` | `"start" \| "end" \| "center" \| "stretch" \| "baseline"` | `"stretch"` | align-items |
| `wrap` | `bool` | `False` | Whether children wrap |
| `gap` | `int` | `2` | Gap between children (Tailwind spacing unit) |
| `id` | `str \| None` | `None` | Unique element ID |
| `class_name` | `str` | `""` | Extra Tailwind classes |

## Notes

`Flex` maps directly to `Row` when `direction="row"` and `Column` when
`direction="column"` on the React side. Prefer `Row`/`Column` for static layouts.

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
