toolqik

191 · CSS

Flexbox Playground

Learn and build flexbox layouts interactively: container and item properties with live preview.

Runs in your browser

Click an item to change its own flex properties.

CSS

  
HTML

  

About this tool

Change the flex container’s properties and see the items rearrange instantly. Click an item to give it its own flex-grow, flex-shrink, flex-basis, align-self or order. The CSS for the container and any customised items is generated as you go, and the layout presets show common real-world patterns.

The two axes

Flexbox lays items out along a main axis (set by flex-direction: a row by default) and aligns them on the cross axis at right angles to it.

  • justify-content distributes items along the main axis: start, centre, end, or with space between them.
  • align-items aligns items on the cross axis. The default, stretch, makes them equal height in a row.
  • align-content only matters when items wrap onto several lines: it distributes the lines.
  • gap adds space between items, never at the edges. No more margin hacks.

Item sizing: grow, shrink and basis

flex-basis is an item’s starting size. Leftover space is shared out in proportion to flex-grow; if there isn’t enough space, items shrink in proportion to flex-shrink. The shorthand flex: 1 means grow 1, shrink 1, basis 0: equal-width columns whatever their content.

Flexbox is one-dimensional: rows or columns. For layouts that line up in both directions, use the CSS Grid Generator.

FAQ

How do I centre something with flexbox?

On the parent: display: flex; justify-content: center; align-items: center. Give the parent a height if you want vertical centring in the viewport.

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

justify-content works along the main axis (horizontal in a row), align-items along the cross axis (vertical in a row). With flex-direction: column they swap.

What does flex: 1 do?

It is flex: 1 1 0: the item may grow and shrink and starts from zero width, so all flex: 1 items end up equal in size.

Why isn’t align-content doing anything?

It only affects multi-line containers. Set flex-wrap: wrap and make sure the items actually wrap.

Flexbox or grid?

Flexbox for one row or column of items, like nav bars and toolbars. Grid for two-dimensional layouts where rows and columns line up.

esc
↑↓ navigate↵ open