CSS FLEXBOX GENERATOR
Dial in flex-direction, justify-content, align-items, wrap, and gap with a live box preview.
In short
Set flex-direction, justify-content, align-items, flex-wrap, and gap with controls and see the layout update live on preview boxes. Copy the generated flexbox CSS — all in your browser.
1
2
3
4
5
.container {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
gap: 12px;
}How to build a flexbox layout
- 1
Choose a flex-direction to set whether items flow in a row or column.
- 2
Pick justify-content to control spacing along the main axis, and align-items for the cross axis.
- 3
Toggle flex-wrap and adjust gap to fine-tune spacing between items.
- 4
Drag the item count slider to see how the layout behaves with more or fewer boxes.
- 5
Copy the generated .container CSS and paste it into your stylesheet.
Questions
- What's the difference between the main axis and cross axis?
- The main axis follows flex-direction (horizontal for row, vertical for column) and is controlled by justify-content. The cross axis runs perpendicular to it and is controlled by align-items. Switching direction from row to column swaps which property does what visually.
- When should I use gap instead of margin?
- gap only adds space between items, not around the outer edge of the container, so you avoid extra margin collapsing or trimming logic on the first/last item. It's supported in all modern browsers for flexbox.
- What does flex-wrap do?
- nowrap (the default) forces all items onto one line, shrinking them if needed. wrap lets items flow onto new lines when they run out of room, and wrap-reverse does the same but stacks new lines in reverse order.
- Do I need to set widths on the flex items?
- Not necessarily — flex items size based on their content by default, then grow or shrink based on flex-grow/flex-shrink (both default to reasonable values). This generator focuses on the container properties; add flex-grow/flex-basis on individual items for more control.
- Is this computed locally?
- Yes — the preview and CSS are generated entirely with client-side JavaScript. Nothing is uploaded.
Related tools
- CSS Variables GeneratorBuild a set of named CSS custom properties and get the generated :root block.
- CSS Grid GeneratorDial in grid-template-columns/rows and gap with a live preview grid.
- CSS Transform GeneratorBuild a translate/rotate/scale/skew transform with a live preview and generated CSS.
- CSS Text Shadow GeneratorLayer up to five text-shadows with a live preview and generated CSS.
- CSS Filter GeneratorDial in blur, brightness, contrast, grayscale, hue-rotate, invert, saturate, and sepia with a live preview.
- CSS Animation GeneratorPick a preset (spin, pulse, bounce, fade, slide, shake) and dial in timing, then copy the @keyframes CSS.
- CSS Button GeneratorDesign a button — colors, padding, radius, border, shadow, hover state — and copy the generated CSS.
- CSS Triangle GeneratorBuild a pure-CSS triangle with the border trick — direction, size, and color — and copy the CSS.
Updated