CODDY Tool

Flexbox Generator

Build a flex layout visually and copy the CSS.

Adjust direction, wrapping, alignment and gap on a live flex container and copy the result. The preview is real flexbox, so what you see is exactly what the CSS produces.

Everything you enter stays in this browser tab. Nothing is sent to our servers, logged or stored.

Loading tool…

About Flexbox Generator

Flexbox is one dimensional: it lays items out along a single axis, and everything else follows from which axis that is. Once flex-direction is row, justify-content moves items horizontally and align-items moves them vertically. Set it to column and those two swap. Almost all confusion with flexbox comes from reaching for the wrong one of that pair.

That is why this shows a live container rather than a diagram. The preview is a real flex container with the properties applied, so changing flex-direction visibly swaps what the other controls do, which is far quicker to internalise than reading that main and cross axes exist.

Items in the preview deliberately vary in height, because align-items does nothing visible when everything is the same size — a static mock-up hides the very property people came to understand.

How to build a flex layout

  1. Pick a direction

    Row or column. This decides which axis the other properties operate on.

  2. Set alignment

    justify-content works along the direction; align-items works across it.

  3. Copy the CSS

    Only the properties that differ from the defaults are included, so the output stays short.

The properties worth knowing

  • justify-content — position along the main axis. space-between is the classic navigation bar layout.
  • align-items — position across the main axis. center is the answer to most vertical-centring questions.
  • align-content — spaces the wrapped lines, and does nothing at all until flex-wrap allows more than one.
  • gap — spacing between items, and far better than margins because it does not add space at the outer edges.
  • flex-wrap — off by default, which is why items shrink rather than wrapping when space runs out.

Frequently asked questions

Why does align-content do nothing?

Because it only spaces wrapped lines, and with flex-wrap set to nowrap there is only ever one line. Set flex-wrap to wrap and it takes effect immediately.

How do I centre something both ways?

justify-content: center and align-items: center on the container. That is the whole answer regardless of direction, which is why flexbox replaced every older centring trick.

Should I use flexbox or grid?

Flexbox for one dimension — a row of buttons, a navigation bar, a card's internal layout. Grid for two — a page layout with rows and columns that must line up. Using flexbox for a two-dimensional layout is the most common reason a layout becomes hard to maintain.

Why do my items shrink instead of wrapping?

flex-wrap defaults to nowrap, so items compress to fit rather than moving to a new line. Set it to wrap and they behave the way most people expect.

All Developer Tools

Flexbox Generator is free to use with no account, no watermark and no usage limits. Last updated 14 August 2026.