CSS Flexbox Playground

Learn and experiment with CSS Flexbox. Adjust container properties and watch the layout update live.

CSS

  

Features

Container properties panel
Add/remove items
Individual item controls
Live layout preview
Generate CSS code

How to Use

1. Adjust container properties (direction, wrap, justify-content, align-items).

2. Add or remove flex items.

3. See the layout update live and copy the CSS.

About this tool

Flexbox arranges items along one axis — a row or a column — and distributes space between them. The trouble is that a handful of properties interact: flex-direction sets the main axis, justify-content aligns items along it, align-items aligns them across it, flex-wrap decides whether they move to a new line, and gap sets consistent spacing. This playground lets you change each property and immediately see how coloured boxes rearrange, which is the quickest way to build intuition or debug a layout that is not behaving. Add or remove items to test wrapping, then copy the generated CSS for the container. For two-dimensional layouts where rows and columns must line up, CSS Grid is usually the better tool.

Frequently Asked Questions

What is the difference between justify-content and align-items?
justify-content distributes items along the main axis set by flex-direction, and align-items positions them on the cross axis. In a row, justify-content works horizontally and align-items vertically; in a column the roles swap.
Why does justify-content not seem to do anything?
It only has an effect when there is free space on the main axis. If items already fill the container, for example because they have flex: 1 or a large width, there is nothing left to distribute.
When should I use gap instead of margins?
gap adds space only between items, never on the outer edges, and it works for both rows and wrapped lines. It is simpler and more predictable than margins, and it is supported for flexbox in all current browsers.
What does flex-wrap change?
With nowrap, items stay on one line and shrink if needed. With wrap, items move to additional lines when they run out of space, and wrap-reverse stacks those lines in the opposite direction.
Should I use Flexbox or Grid?
Use Flexbox for one-dimensional arrangements such as navigation bars, button groups or centring content. Use Grid when you need items aligned in both rows and columns, such as card galleries or page layouts.

Related Tools