One axis, decided by the content

Flexbox lays a set of items out along a single line and lets their own sizes drive the result. The container does not say how wide anything is; it says which direction to flow and how to distribute whatever space is left over. That is why it is the right tool when you do not know in advance how many items there will be, or how big each one needs to be: a navigation bar with a variable number of links, a row of tags, a toolbar whose buttons size themselves from their labels, two buttons pushed to opposite ends of a card footer.

The generator's starting state produces exactly this:

.flex-container { display: flex; flex-direction: row; justify-content: center; align-items: center; flex-wrap: nowrap; gap: 12px; }

Main axis versus cross axis

Everything in flexbox is defined relative to two perpendicular axes, and the single most confusing thing about the module is that the two alignment keywords swap physical meaning when you change flex-direction.

So in a row, justify-content moves things left and right and align-items moves them up and down. Switch to a column and the two swap over entirely, with no renaming. When a flexbox layout is behaving inexplicably, the first question to ask is which axis you are actually working on.

The controls, and what each one does

PropertyValues offeredEffect
flex-directionrow, column, and their reversed formsSets which axis is the main one and which way it points.
justify-contentflex-start, center, flex-end, space-between, space-around, space-evenlyPacks items at one end or spreads the leftover space between them. Note that space-around gives each item equal space on both sides, so the outer gaps are half the inner ones, whereas space-evenly makes every gap identical including the ends.
align-itemsstretch, flex-start, center, flex-end, baselineCross-axis position per item. stretch is the default and makes items fill the container's cross size; baseline lines up the first line of text in each item, which is what you want when a row mixes font sizes.
flex-wrapnowrap, wrapWhether items may break onto additional lines when they run out of room.
align-contentstretch, flex-start, center, flex-end, space-between, space-aroundDistributes the wrapped lines themselves on the cross axis.
gap0 to 80 pxSpace between items and between wrapped lines.

That last control is conditional on purpose. align-content only has an effect on a container that has wrapped onto multiple lines. With flex-wrap: nowrap the property is ignored entirely, which is why the generator hides it until you choose wrap — and why setting it on a single-line container is such a common dead end.

There is also a visibility trap with justify-content: if the items already fill the line, there is no leftover space to distribute, so changing the value changes nothing on screen. The preview gives each box a fixed 64px width precisely so that free space exists and the buttons have a visible effect.

What the generator does not write

Notice that the output contains container rules only. The items' own flexibility — flex-grow, flex-shrink and flex-basis, usually written together as flex: 1 — is not emitted, because the preview boxes have explicit sizes instead. The moment you want one child to absorb the leftover space rather than just sit in it, that is the declaration you add:

.flex-container > .search { flex: 1; }

With justify-content: flex-start that turns a logo, a search field and a button into the classic header bar, where the search field expands to fill everything the other two do not use.

Where flexbox goes wrong

When flexbox is the right choice

Reach for it when the layout is a single sequence and the content should decide the sizes: navigation bars, button groups, breadcrumb trails, media objects with an avatar beside text, form rows, vertically centring one item, distributing an unknown number of cards along one line, or pushing a footer to the bottom of a short page. Reach for grid instead when columns and rows both matter and tracks must line up with each other.

Questions we hear about flexbox

Why does justify-content do nothing?

Because there is no free space left on the main axis. Either the items already fill the line, or one of them has grown to absorb everything. Check the items' widths and any flex: 1 first.

Why is align-content ignored?

It applies only to multi-line containers. Set flex-wrap: wrap and make sure the items actually overflow the line; otherwise align-items is the property you are looking for.

How do I centre something perfectly?

display: flex; justify-content: center; align-items: center; on the parent centres the child on both axes, and it works without knowing the child's size. That is the generator's default state.

Can I use gap in flexbox everywhere?

Yes. Space between flex items via gap is supported in all current browsers, including in the row and column directions.

Should I still use floats or inline-block?

No. For a one-dimensional sequence, flexbox now covers every case those techniques handled, with fewer side effects and no clearing hacks.