Set direction, wrapping, justification, alignment and gap on a live flex container, then copy only the properties that differ from the defaults.
This distributes the lines of a wrapping container, so it needs enough items to wrap onto a second line before it does anything visible.
.flex-container {
display: flex;
flex-wrap: wrap;
gap: 12px;
}CSS Flexbox Generator runs entirely on your device — nothing is uploaded.
You’re on the Free plan. Compare plans
Flexbox has one main axis and one cross axis, and nearly every flexbox confusion is about which is which. `flex-direction` decides: in a row the main axis runs horizontally, in a column it runs vertically. `justify-content` always works along the main axis and `align-items` always works across it, so switching the direction silently swaps what those two properties appear to do. Seeing the items move as you change it is faster than re-reading the spec.
`align-items: stretch` is the default, and it is why a column of flex items all end up the same width without anyone asking them to. That one default explains a large share of the layouts people describe as mysteriously wrong.
`gap` replaced margins on flex children and it is better in every way that matters: no margin on the first or last item to undo, no collapsing, and no negative margin on the container. It is supported everywhere current, so there is no reason left to space flex items with margins.
The output includes only the properties that differ from the browser's defaults. A `display: flex` container is already `flex-direction: row`, `flex-wrap: nowrap`, `justify-content: flex-start` and `align-items: stretch`, and writing those out does nothing but make the rule longer and harder to scan for the one line that is actually doing something.
justify-content distributes items along the main axis; align-items positions them across it. Which direction that is depends entirely on flex-direction, which is why they seem to swap when you change a row to a column.
Because align-items defaults to stretch. Set it to flex-start, center or baseline and each item takes its own size on the cross axis.
Only when there are multiple lines, which means only when flex-wrap is on and the items have actually wrapped. On a single line it has no effect at all.
Gap. It spaces between items without adding space at the ends, needs no undoing on the first or last child, and is supported in every current browser.
Flexbox for content in one direction where the items size themselves — a toolbar, a row of tags. Grid when you need rows and columns to line up with each other. The two work together; a grid cell can be a flex container.