Polyatic Flexbox Generator

CSS Flexbox Generator

Build a flexbox layout visually — set flex-direction, wrap, justify-content, align-items, align-content and gap, add or remove items, and copy the exact container CSS. The preview is a real flex container, so it lays out exactly like the browser will.

flex-direction
flex-wrap
justify-content (main axis)
align-items (cross axis)
align-content (wrapped lines only)
gap12px
Flex items4

Add items until they wrap (turn flex-wrap on) to see how align-content spaces the rows. The items themselves are plain boxes — this tool builds the container.


            
          

Runs entirely in your browser. The preview is a real flex container and the CSS is built on your own device with plain JavaScript — nothing you design is uploaded, and the page keeps working offline.

What flexbox is for

Flexbox lays a row or column of items out along one axis and gives you precise control over how leftover space is distributed. You turn any element into a flex container with display: flex; its direct children become flex items automatically. Everything else — direction, wrapping, alignment, spacing — is a handful of properties on that same container. This tool builds those container properties visually and copies them as a clean block you paste into your stylesheet.

Main axis vs cross axis — the one idea that unlocks it

Flexbox has two axes. The main axis runs in the direction flex-direction points: horizontal for row, vertical for column. The cross axis is the perpendicular one. justify-content always positions items along the main axis; align-items always positions them along the cross axis. That is why switching direction feels like the controls swap places — they do, relative to the screen. To center something perfectly, set both: justify-content: center; align-items: center;.

Worked example: a centered nav bar

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

Logo on the left, links pushed to the right, everything vertically centered, and a 24px minimum gap between items. Change space-between to center and the whole group clusters in the middle instead. This is the exact CSS this tool emits — copy it and adjust the numbers.

align-content only matters when things wrap

With flex-wrap: nowrap (the default) every item stays on one line and align-content does nothing at all. Turn wrapping on and add enough items to spill onto a second row, and align-content starts distributing space between the rows. If you have ever set align-content and seen no change, this is almost always why — it is a multi-line-only property, and the preview here makes that obvious once you add items past the wrap point.

What this tool does not do (and where to go next)

This is a container-only builder. It covers the six parent properties and deliberately leaves out the per-item properties — flex-grow, flex-shrink, flex-basis, the flex shorthand, order, and align-self — because those live on individual children, not the container. In real layouts you often add flex: 1 to one child so it soaks up spare space, or order: -1 to move an item without touching the HTML; drop those onto the specific items after pasting the container block from here. The output also omits any property left on its default, so the shortest correct CSS is what you copy. For neighbouring styling jobs, the CSS Gradient Generator, Box-Shadow Generator and Border-Radius Generator build the values that go inside the boxes you have just arranged.