Component for creating unidimensional layouts.
Changing visual order creates a disconnect between content and presentation and is, therefore, bad for accessibility. For this reason, the flex-direction: row-reverse and flex-direction: column-reverse options are omitted.
Component for creating unidimensional layouts.
| Prop | Type | Default | Description |
|---|---|---|---|
| justify | 'start' | 'center' | 'end' | 'between' | 'start' | The alignment of items along the main axis. |
| items | 'start' | 'center' | 'end' | 'stretch' | 'start' | The alignment of items along the cross axis. |
| gap | 0 to 20 | 0 | The gap between items. |
| orientation | 'horizontal' | 'vertical' | 'horizontal' | The orientation of the layout. |
| inline | boolean | false | Whether the flex layout is inline or not. |
| wrap | boolean | false | Whether items should wrap to multiple lines. |
Flexbox loses a lot of its power if you make it wrap. If you need to wrap, you should probably use a grid instead.
If you set <Flex inline />, the div has the least width possible, so the justify prop has no meaning because the items won't have any extra horizontal space for the justify option to matter.
If you set <Flex items="stretch" /> and the children have a fixed height, items="stretch" will be ignored.
<Flex inline gap="6" className="mt-4 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex gap="6" className="mt-4 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex justify="center" gap="6" className="mt-4 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex justify="end" gap="6" className="mt-4 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex justify="between" gap="6" className="mt-4 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex gap="6" className="mt-4 h-32 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex items="center" gap="6" className="mt-4 h-32 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex items="end" gap="6" className="mt-4 h-32 rounded-md bg-slate-200 p-4"> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /> <div className="h-10 w-10 rounded-sm bg-slate-600" /></Flex><Flex items="stretch" gap="6" className="mt-4 h-32 rounded-md bg-slate-200 p-4"> <div className="w-10 rounded-sm bg-slate-600" /> <div className="w-10 rounded-sm bg-slate-600" /> <div className="w-10 rounded-sm bg-slate-600" /> <div className="w-10 rounded-sm bg-slate-600" /> <div className="w-10 rounded-sm bg-slate-600" /></Flex>Here's the <Flex /> component in action.