Skip to content
toolgrid

No tool found. Try another word.

CSS Flexbox Generator

Build flexbox layouts interactively: direction, wrap, justify-content, align-items, align-content and gap, with a live preview and ready-to-copy CSS.

CSS

    

Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.

How to use the CSS Flexbox Generator

  1. 1 Set the flex direction, wrapping, alignment and gap.
  2. 2 Change the number of items and watch the preview; resize the preview box by dragging its corner.
  3. 3 Copy the CSS.

About the CSS Flexbox Generator

Flexbox is the CSS layout model for arranging items in a row or a column: navigation bars, toolbars, card rows, centering things vertically. The container decides the direction (flex-direction), whether items wrap to new lines (flex-wrap), how they are spaced along the main axis (justify-content) and how they line up across it (align-items).

The playground shows the effect of every property immediately on numbered boxes of different heights, so you can see for example the difference between space-between, space-around and space-evenly, or between stretch and center. align-content only matters when items wrap onto several lines, which is why it only appears in the CSS when wrapping is on.

With "equal width items" each item gets flex: 1 1 0, so they share the available space equally regardless of their content. gap adds space between items without margins at the edges and is supported in flexbox by all current browsers.

Frequently asked questions

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

justify-content positions items along the main axis (horizontal in a row), align-items across it (vertical in a row). With flex-direction: column the axes swap.

How do I center something with flexbox?

On the container: display: flex; justify-content: center; align-items: center.

When does align-content do anything?

Only when there are several lines of items, so with flex-wrap: wrap and enough items to fill more than one line.

Flexbox or grid?

Flexbox for one dimension (a row or a column of items), grid for two dimensions (rows and columns at the same time).