CSS Flexbox Generator — Visual Playground
- This tool runs entirely in your browser. Nothing you enter or upload is sent to a server.
Preview — click an item to edit it
Container
Only applies when items wrap.
Item 1
CSS
.container {
display: flex;
justify-content: center;
align-items: center;
gap: 12px;
}About this tool
Change the container properties — direction, wrap, justify-content, align-items, align-content and gap — and see the items rearrange instantly. It’s the fastest way to understand what each property does. You can show between 1 and 12 items to test how the layout behaves with more or fewer children.
Select an item to set its own flex-grow, flex-shrink, flex-basis, order and align-self, for layouts like a sidebar that stays fixed while content stretches. Presets such as Centre everything, Navbar, Wrap cards, Vertical stack and Evenly spaced set up a common layout in one click, and are a good way to see how the properties combine.
Copy the container and item CSS straight into your project. Only values that differ from the browser defaults are written, so the output stays short: a centred layout is display: flex, justify-content: center and align-items: center. Item rules are named .item-1, .item-2 and so on, so rename the selectors to match your own markup.
Some things trip people up. justify-content and align-items swap their axes when you change to column, align-content has no effect unless items wrap (the tool notes this), and flex-basis beats width on the main axis. By default items are allowed to shrink, which is why wide content squeezes instead of overflowing. Flexbox lays out in one dimension, so for rows and columns together use the Grid generator. The playground runs in your browser; nothing is sent anywhere.
Frequently asked questions
What is the difference between justify-content and align-items?
justify-content positions items along the main axis (horizontal in a row), align-items along the cross axis (vertical in a row). Switching flex-direction swaps the axes.
How do I centre something with flexbox?
On the parent: display: flex; justify-content: center; align-items: center.
What does flex: 1 do?
It sets flex-grow to 1 so the item takes up the available space, sharing it equally with other flex: 1 items.
Why is align-content doing nothing?
align-content only works when there is more than one line of items, which needs flex-wrap set to wrap. In a single line, use align-items instead.
What do flex-grow, flex-shrink and flex-basis mean?
flex-basis is the starting size of an item, flex-grow decides how leftover space is shared out, and flex-shrink decides how items give up space when they do not fit. They are written together as flex: grow shrink basis.
How do I put one item at the far end of a row?
Add margin-left: auto to that item. Auto margins absorb the free space in a flex container. The generator does not output margins, so add that line to your own CSS.
Should I use flexbox or grid?
Use flexbox for a single row or column, such as navbars, button groups and card rows. Use grid when you need to control rows and columns together, such as a page layout or a gallery.