How do I use the flexbox generator?
Pick a flex direction, then adjust justify-content, align-items, wrapping and gap while watching the numbered boxes rearrange in the live preview. Change the item count to see how your layout behaves with more or fewer elements. The CSS below the preview updates with every change — press Copy CSS and paste it into your stylesheet, then rename .container and .item to your own class names. Try the Sample for a centred, wrapping row.
What is CSS flexbox?
Flexbox (the Flexible Box Layout Module) is CSS's one-dimensional layout system: a container lays its children out along a single row or column, distributing space and aligning them without floats or fixed widths. It solved the classic headaches of centring content, equal-height columns and evenly spaced navbars. Since 2015 it has been supported by every modern browser, and it remains the first tool most developers reach for when building component layouts.
justify-content vs align-items
These two properties are the heart of flexbox, and they work on perpendicular axes. justify-content aligns items along the main axis — horizontally for row, vertically for column. align-items aligns them across it, on the cross axis. So in a row, justify-content: center centres items left-to-right, while align-items: center centres them top-to-bottom. Set both to center and you have the famous two-line trick for perfectly centring anything.
Flex direction and wrapping explained
flex-direction chooses the main axis: row (left to right), row-reverse, column (top to bottom) or column-reverse. flex-wrap decides what happens when items run out of room — nowrap squeezes them onto one line, while wrap lets them flow onto new lines, which is essential for responsive card grids. The gap property adds consistent spacing between items without margins, and this generator lets you test all combinations live.
Flexbox vs grid: which should I use?
Use flexbox when content should flow in one direction and size itself — navbars, button groups, card rows, toolbars. Use CSS grid when you need to control rows and columns at the same time — page layouts, dashboards, galleries. They are complements, not rivals: many real layouts use grid for the page skeleton and flexbox inside each component. If you are arranging items in a line, flexbox is almost always the simpler answer.
Is it free and private?
Yes. The flexbox generator is completely free, needs no sign-up, and runs entirely in your browser. Your settings and generated CSS are never uploaded or stored. It works on phones, tablets and desktop computers.