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.

A
B
C
A
B
C
A
B
C
A
B
C

2. Justify (main axis)

Distributes space along the main axis (horizontal for flex-row).

1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3

3. Align Items (cross axis)

Positions items on the perpendicular axis. Mix variable heights to see the difference.

sm
md
lg
sm
md
lg
sm
md
lg
sm
md
lg
sm
md
lg

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.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8

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
flex-1
flex-1
flex-1 (grows)
flex-none
flex-1 with long text that will truncate gracefully
basis 8rem
basis 14rem
basis 6rem

6. Gap Scale

Use gap-* instead of margins between flex children. Gaps do not collapse and respect flex-wrap rows too.

A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D

7. Real-world Patterns

Practical compositions you'll reach for most often in a builder context.

Page title that can be very long and will truncate
Save
AV
Username
Comment body that wraps naturally because the container is flex-col
Email address input
Subscribe
Headline
Subheadline
CTA Button
Brand
Links
Legal
Social

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.

No items to display
Label
Supercalifragilisticexpialidocious-slug-that-overflows-without-min-w-0
Design
UX
UI
Tailwind
DaisyUI
Alpine
Commerce
Layout
Flex
Grid
CSS
HTML
Builder
Widget
Block
Token
Theme
Dark
Light
Responsive