Flexbox Generator & Playground
Build CSS flexbox layouts visually — direction, wrap, justify-content, align-items and gap with a live preview. Copy the generated CSS for free.
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: stretch;
align-content: stretch;
gap: 8px;
}About Flexbox Generator & Playground
Configure a flex container visually — direction, wrap, justify-content, align-items, align-content and gap — and watch the preview update instantly.
Copy clean, minimal CSS with only the properties you changed. Runs entirely in your browser.
Flexbox distributes space along one axis: justify-content arranges along the main direction, align-items across it, and the confusion between them is the eternal beginner trap — swap flex-direction and the two swap meaning. The mental model that sticks: justify is always along the flow direction, align always across it.
The patterns that cover 90% of real use: perfect centering (justify + align both center — three lines total), space-between for navbars with logo-left-menu-right, and flex-grow ratios for proportional columns. Gap ended the margin-hack era; use it. And the shrinking surprise: flex items shrink by default — flex-shrink: 0 is the fix when content gets crushed unexpectedly.
How to use Flexbox Generator & Playground
- Set the container properties on the left — the stage shows the layout live.
- Adjust item count and gap to test wrapping behavior.
- Copy the generated .container CSS block.
Frequently asked questions
What's the difference between justify-content and align-items?
justify-content distributes items along the main axis (horizontal in row), while align-items aligns them on the cross axis — flip flex-direction to column and the axes swap.
When do I need align-content?
Only with flex-wrap enabled and multiple lines — it controls spacing between the wrapped lines; on a single line it does nothing.
Flexbox or Grid?
Flexbox for one-dimensional layouts (a nav bar, a row of cards), Grid for two-dimensional page layouts — try the CSS Grid Generator for the other half.
Why do my flex items shrink?
flex-shrink defaults to 1 — items compress to fit rather than overflow. Set flex-shrink: 0 or an explicit flex-basis when items must hold their size; this is the most common flexbox surprise.
Flexbox or grid for this layout?
One-dimensional distribution — flexbox. Two-dimensional arrangement — grid. The practical division: components are usually flex, page layout usually grid, and they nest inside each other constantly.