Flex Layout
Flexbox utility patterns: direction, alignment, wrapping, gap, and grow/shrink control for real-world UI composition.
1. Direction
Controls the main axis. flex-row (default) lays items left→right; flex-col stacks them top→bottom.
flex-row (default)
flex-row-reverse
flex-col
flex-col-reverse
2. Justify (main axis)
Distributes space along the main axis (horizontal for flex-row).
justify-start
justify-center
justify-end
justify-between
justify-around
justify-evenly
3. Align Items (cross axis)
Positions items on the perpendicular axis. Mix variable heights to see the difference.
items-start
items-center
items-end
items-stretch
items-baseline
4. Wrap
flex-wrap allows items to reflow onto new lines when the container is too narrow. Common for tag clouds, badge groups, and responsive button bars.
flex-nowrap (default) — items overflow
flex-wrap — items reflow
5. Grow / Shrink / Basis
Controls how individual items fill available space. flex-1 = grow + shrink + basis 0 (equal share). flex-none = fixed size, no flex.
flex-1 — all items share space equally
mixed: grow + fixed + shrink
flex-basis — explicit starting size before flex kicks in
6. Gap Scale
Use gap-* instead of margins between flex children. Gaps do not collapse and respect flex-wrap rows too.
gap-1 (4px)
gap-2 (8px)
gap-4 (16px)
gap-6 (24px)
gap-8 (32px)
7. Real-world Patterns
Practical compositions you'll reach for most often in a builder context.
Toolbar — icon + stretched title + actions
Media object — avatar + body text block
Inline form row — input grows, button fixed
Centered hero — flex-col + items-center + justify-center
Footer row — justify-between with wrapping columns
8. Interactive Playground
Combine any props live. The generated Tailwind classes are shown below the preview.
9. Edge Cases
Scenarios that break naive implementations. Always test with real data.
Zero items — empty container should not collapse layout
Long single word — min-w-0 + truncate prevents overflow
Many items with wrap — 20 tags, container ~400px wide