What the Flexbox Playground does
The Flexbox Playground shows what each flexbox setting does, as you change it. Set the container’s direction, wrapping, justify-content, align-items, align-content and gap, and add up to 12 items. Click an item to give it its own flex-grow, flex-shrink, flex-basis, order and align-self. The CSS lists only the settings that differ from the defaults.
How to use it
- Choose the container settings from the lists.
- Add or remove items with + and −.
- Click an item and change its grow, shrink, basis, order or alignment.
- Copy the CSS.
Example
With flex-wrap set to wrap, justify-content to space-between and item 2 given a grow of 2, the tool writes .container { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; } and .item:nth-child(2) { flex: 2 1 auto; }. Item 2 then takes the spare space on its row.
The two axes
justify-content spaces items along the main axis, which runs across in a row and down in a column. align-items lines them up on the other axis. align-content only matters when items wrap onto several lines, and spaces those lines.
flex: 1 1 0 makes items share space equally whatever their content. order changes the visual order only; screen readers and the Tab key still follow the HTML, so keep important order in the HTML itself.
A quick recipe for a navigation bar: justify-content set to space-between with align-items set to center puts the logo on the left and the links on the right, all lined up on one middle line.
Questions people ask
Is anything uploaded?
No. Everything is worked out in your browser, so your colours, designs and images stay on your device.
Why do items have different heights?
So you can see alignment work. With align-items set to stretch, they become the same height.
What is flex-basis?
The starting size of an item before spare space is shared out or taken away, such as 200px or auto.
Does gap work with flexbox?
Yes, in every current browser.