Tools
Flexbox Playground
Set the flex container and item properties, watch the layout change live, and copy the CSS and HTML. Only values that differ from the defaults end up in the code.
Flexbox playground
Runs entirely in your browser. Nothing you type is sent to a server.
Preview
Drag the bottom-right corner to resize
CSS
.container {
display: flex;
}
HTML · 3 items
<div class="container"> <div class="item item-1">1</div> <div class="item item-2">2</div> <div class="item item-3">3</div> </div>
About the flexbox playground
Flexbox lays items out along one axis. The container decides the direction, wrapping, spacing and alignment; each item decides how much it grows, shrinks and where it starts. This playground puts every one of those properties on a control and shows the result in a live preview, so you can see what justify-content: space-between or flex-grow: 1 actually does before you write it.
The generated CSS only contains values that differ from the defaults, so you never copy noise such as flex-direction: row. Every item is one numbered <div> in the HTML, and per-item rules target its .item-N class. Remove an item and the ones after it move up a number, keeping their own settings.
Invalid values (a negative gap, a flex-grow below zero, anything containing ; or {) are never written to the CSS: the field turns red and the summary above the code says what was left out. Everything runs in your browser; nothing you type is sent anywhere.
Worked example: centre anything
Set justify-content and align-items to center and add a gap. The container rule is all you need; the items need no CSS at all.
.container {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}align-items centres on the cross axis, so give the container a height to see the vertical centring.
.container {
display: flex;
column-gap: 16px;
}
.item-1 {
flex-shrink: 0;
flex-basis: 160px;
}
.item-2 {
flex-grow: 1;
}Frequently asked questions
What is the difference between justify-content and align-items?
justify-content distributes items along the main axis (horizontal for flex-direction: row), while align-items positions them on the cross axis. Switching to column swaps which way each one works.
Why does align-content do nothing?
align-content only spaces out lines, so it has an effect only when flex-wrap is wrap and the items actually wrap onto more than one line.
What does flex-basis: 0 with flex-grow: 1 do?
Every item starts from zero width and the free space is shared by the flex-grow ratios, so items with the same grow value end up exactly the same width whatever their content.
Does order change the HTML?
No. order only changes the visual order; screen readers and keyboard focus still follow the source order, so keep the HTML in a sensible order.
How many items can I add?
Up to 100. Above that the count field says so and the output keeps the last valid number of items, so the code never claims more items than it contains.