This page writes the CSS for a flex container. Choose the direction, the main-axis and cross-axis alignment, the wrapping behaviour and a gap, and the page returns six declarations plus a live preview of three items. The output is container-only: it does not style the children, because their size, order and growth are separate decisions.
It is a quick way to get the six lines right without remembering which property controls which axis, and a way to see how space-between, baseline or wrap-reverse actually look before you commit them to a stylesheet.
What the output contains
The rule is always the same shape: display: flex, then flex-direction, justify-content, align-items, flex-wrap and gap. That is six declarations, and the stats panel confirms the count. The class is named .flex-container; rename it or copy the declarations into an existing rule.
No width, height, padding or background is written. The preview styles its own box so the items are visible, but those styles are not part of the CSS. A container with no height and no content will collapse, so the parent layout still matters.
The generator adds no vendor prefixes. Flexbox and flex gap are supported in current Chrome, Firefox, Safari and Edge without them. If you must support a browser from before 2021, check its gap support separately; the older workaround used margins on the children.
Main axis and cross axis
In a row, the main axis runs horizontally: justify-content places items left to right and align-items places them top to bottom. In a column, the axes swap: justify-content now controls vertical placement and align-items controls horizontal placement. The checklist repeats this because it is the most common source of confusion when a layout is switched from row to column.
flex-start, center and flex-end pack the items at the start, middle or end of the main axis. space-between puts the first item at the start and the last at the end, with equal gaps between. space-around gives each item equal space on both sides, so the outer edges get half a gap. space-evenly makes every gap, including the outer ones, the same size.
On the cross axis, stretch is the default: items with no fixed cross-size fill the container. baseline aligns the first line of text in each item, which is useful when the items contain different font sizes. The other values pack the items at the start, centre or end of the cross axis.
Wrapping and the gap
With nowrap, flex items shrink to stay on one line. That is often not what a card grid wants: on a narrow screen the items can become too small to read. The checklist warns whenever nowrap is selected. wrap lets items move to a new line when they run out of room, and wrap-reverse does the same in the opposite cross-axis direction.
The gap slider runs from 0 to 80 pixels and is written as a pixel value. gap applies between rows and columns, so a wrapped layout gets the same spacing in both directions. It replaces the old margin-based spacing and does not add space around the outer edge of the container.
If the items still overflow with wrapping on, the cause is usually a child with a fixed width wider than the container or a min-width that prevents shrinking. The container CSS cannot fix that; inspect the child rules.
A worked example
The default settings produced a row container with space-between justification, centred cross-axis alignment, no wrapping and a 16-pixel gap.
| Settings | Result |
|---|---|
| row, space-between, center, nowrap, 16 | display: flex; flex-direction: row; justify-content: space-between; align-items: center; flex-wrap: nowrap; gap: 16px; |
| column, center, stretch, wrap, 0 | Six declarations with flex-direction: column and gap: 0px |
| row-reverse, space-evenly, baseline, wrap-reverse, 48 | Six declarations with the reversed and baseline values as selected |
The second run is the one that changes the mental model: in a column, justify-content: center centres the items vertically, and align-items: stretch makes them fill the width. The same two values in a row would centre them horizontally and stretch them vertically.
The third run put the items in reverse order and aligned their text baselines. Because wrapping is wrap-reverse, a new line appears above the first line rather than below it. The preview shows the order, which is easier than reasoning about it from the property names.
What the container does not control
Child sizing is the big omission. flex-grow, flex-shrink, flex-basis, order, align-self and individual margins all live on the items. A common layout uses the container for direction and gap, then gives one child flex: 1 so it takes the remaining space. That rule has to be written by hand.
The generator also does not set min-height, padding or a background. Those are visual decisions, and keeping them out means the copied rule can drop into an existing component without overriding its look. If the component already sets display: grid, remove that declaration or the last one wins.
For a complete layout, pair this rule with the gradient generator for the background and the box shadow generator for depth. The CSS beautifier will tidy the rest of the stylesheet around it.