CSS Flexbox Playground

Try every flexbox property on live boxes: direction, wrap, justify, align, gap and per-item grow, shrink and order.

Runs in your browser. Nothing is uploaded.

Change the container, then click an item to change it on its own
Flex container
Preview click an item to pick it · drag the corner to resize
Item 1

How to use the CSS Flexbox Playground

  1. Change the container settings, direction, wrapping, justify-content, align-items, align-content and gap, and watch the boxes move.
  2. Set how many items there are, from 1 to 12.
  3. Click an item to select it, then change its own flex-grow, flex-shrink, flex-basis, align-self and order.
  4. Drag the bottom-right corner of the preview to see how the layout reacts to width.
  5. Copy the CSS and HTML. Only settings that differ from the defaults are included.

Learn flexbox by playing with it

Flexbox is the CSS layout tool for arranging items in a row or a column: navigation bars, toolbars, card footers, centred content and form rows. It has a dozen properties whose names are easy to mix up. Reading about justify-content versus align-items helps less than seeing it, so this playground lets you change every property and watch numbered boxes rearrange instantly.

Container properties

  • flex-direction sets the main axis: row, column, or reversed versions.
  • flex-wrap lets items move onto new lines when there isn’t room.
  • justify-content spreads items along the main axis: start, centre, end, or with space between, around or evenly.
  • align-items lines items up on the cross axis: stretch, start, centre, end or text baseline.
  • align-content spaces the lines themselves when items wrap.
  • gap puts even space between items without margins.

Item properties

Click any box to select it, then give it its own settings:

  • flex-grow decides how much leftover space it takes, so a value of 1 on one item pushes the rest aside.
  • flex-shrink decides how much it gives up when space is short.
  • flex-basis is its starting size before growing or shrinking.
  • align-self overrides align-items for that item.
  • order moves it visually without changing the HTML.

Copy only what matters

The CSS output lists just the properties that differ from the defaults, for the container and for each changed item, so you can paste it straight into your stylesheet. The HTML shows the matching markup.

Drag the corner of the preview to see how the layout behaves on narrow screens. When you need rows and columns that line up in both directions, move on to the CSS Grid Generator. Everything runs locally in your browser.

Frequently asked questions

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

justify-content places items along the main axis, the direction set by flex-direction (left to right for a row). align-items places them on the cross axis (top to bottom for a row). When you switch to column, the two swap roles.

Why doesn’t align-content do anything?

align-content only works when items wrap onto several lines. Set flex-wrap to wrap and add enough items, or narrow the preview, to see it.

What does flex 1 1 auto mean?

It is shorthand for flex-grow 1 (take a share of extra space), flex-shrink 1 (shrink when space is short) and flex-basis auto (start from the item’s own size).

When should I use grid instead?

Use flexbox for one row or one column of items, like a navigation bar or a row of buttons. Use CSS Grid when you need rows and columns that line up together.

Is anything uploaded?

No. Everything runs in your browser.

Tutorials