How to use the flexbox playground
- Pick a pattern or start with three items in a row.
- Set the container: direction, wrapping, how items are distributed along the main axis (
justify-content) and aligned on the cross axis (align-items), plus the gap. - Select an item and change how it grows, shrinks, its starting size (
flex-basis), its order and its own alignment. - Add or remove items to see how wrapping and distribution behave.
- Export CSS (only non-default values are written), Tailwind utilities, HTML, SCSS or React.
How flexbox works: the two axes
Flexbox works along a main axis, set by flex-direction, and a cross axis perpendicular to it. justify-content distributes items on the main axis; align-items aligns them on the cross axis. When you switch to column, the two swap, which is the most common source of flexbox confusion.
Worked examples
Example 1: a navigation bar
Load Navbar: the logo, links and an action button, with the middle item growing to push the button to the right edge. align-items: center lines everything up vertically.
Example 2: a media object
Load Media object: a fixed-size image (flex-shrink: 0, basis 96px) beside text that takes the remaining space. It’s the classic comment or notification layout.
Example 3: a responsive tag list
Load Tags: items wrap onto new lines with an 8px gap. Use it for keyword chips, filter buttons and badges.
Tailwind output
The Tailwind export uses standard utilities where they exist (flex, justify-between, items-center, gap-4, flex-1, shrink-0), and arbitrary values only where needed, such as basis-[220px].
Common mistakes
- Expecting items to shrink below their content. Text and images have a minimum content size; add
min-width: 0to let a flex item shrink further. - Using
flex: 1when you meant equal widths with different content.flex: 1(basis 0%) gives equal widths;flex: auto(basis auto) shares only the leftover space. - Too many items without wrapping. Turn on
flex-wrap: wrapso rows can break on small screens.
Flexbox or grid?
Use flexbox for one row or column of items, and grid when you need rows and columns to line up together.