CSS Flexbox Playground

Pick flex container properties and the layout in the result area updates instantly, with the ready CSS shown below. Click an item to set its flex-grow, flex-basis, order or align-self.

Container (display: flex)
Selected item: none

Click an item in the result area to edit its properties.

Items: 3
Result
CSS

Use cases

  • Understanding what each flexbox property does by changing it and seeing the result
  • Finding the right alignment for a menu, a row of cards or a centered block
  • Copying the ready CSS, or opening the example in the HTML Editor to keep building

FAQ

What is flexbox?

Flexbox (CSS Flexible Box Layout) lays elements out in a single row or a single column. You turn it on with display: flex on the parent element — the container — and all of its direct children become flex items.

What is the difference between justify-content and align-items?

justify-content distributes items along the main axis, while align-items aligns them along the cross axis. By default (flex-direction: row) the main axis is horizontal; choose column and the axes swap.

Why does align-content do nothing?

align-content distributes the lines of flex items and only works in a container that wraps — flex-wrap: wrap or wrap-reverse. With flex-wrap: nowrap (the default) all items sit on one line and align-content does not apply.

What does flex: 1 mean?

It is shorthand for flex-grow: 1, flex-shrink: 1 and flex-basis: 0%. Items with flex: 1 share the free space equally. In the playground you can set these values one by one and watch how they change the sizes.

Flexbox or CSS Grid?

Flexbox lays items out in one direction — a row or a column. CSS Grid controls rows and columns at the same time. Flexbox is handier for menus, button rows or centering; grid suits page layouts.

Does order change the order for screen readers?

No. order only changes the visual order: the HTML order — and with it the reading order and Tab key order — stays the same. So put the order that matters in the markup itself.

Related tools