🔒 100% private — runs in your browser, nothing is uploaded

CSS Flexbox Generator

Arrange a flex container visually — direction, justify-content, align-items, wrap and gap — and copy the container CSS.

Flexbox is the one-dimensional layout system: a container picks a main axis, and its items are laid along that axis, sized by their content, and distributed by rules you set. Two properties do most of the work and are constantly confused — justify-content distributes items along the main axis, align-items positions them on the cross axis. With the default row direction, justify is horizontal and align is vertical; switch to column and the two swap jobs. The worked example is the universal navbar: display: flex; justify-content: space-between; align-items: center; gap: 16px — the logo sits at the left edge, the links at the right edge, everything is vertically centred, and items never touch. That single declaration replaced a decade of floats and inline-block hacks, and it is the output this generator produces when you pick row / space-between / center.


Everything runs in your browser; your values are never uploaded, stored or put into a link. The CSS targets the flex container; the four preview boxes are ordinary items inside it.

Quick answers

How do I space nav items to opposite edges with flexbox?

On the nav container: display: flex; justify-content: space-between; align-items: center. The first item pins to the left edge, the last to the right edge, and any middle items spread between them.

Add gap: 16px so items keep a minimum separation when the bar gets narrow; space-between only distributes the leftover space.

How do I vertically center items in a flex row?

align-items: center on the container. In a row, align-items controls the vertical (cross) axis, so center vertically centres every item against the tallest one — or against the container if it has an explicit height.

If only one item should sit differently, that item takes align-self — a per-item override this container generator intentionally leaves to your stylesheet.

How to use

  1. Pick the direction: row lays items left to right, column stacks them top to bottom; the reverse values flip the order.
  2. Set justify-content to distribute items along the main axis — space-between pushes the first and last items to the edges.
  3. Set align-items for the cross axis (center is the usual choice for toolbars), choose whether items may wrap, and set the gap.
  4. Copy the generated CSS onto your container; the preview boxes are ordinary items, so what moves on screen is what your items will do.

About this tool

The justify values differ in where the leftover space goes: flex-start and flex-end pack items at one end, center groups them in the middle, space-between puts all the space between items (edges flush), space-around gives every item equal space around it (so the edge gaps look half-sized), and space-evenly makes every gap — edges included — identical. align-items defaults to stretch, which is why flex children so often come out equal height: items without a fixed cross size are stretched to the line. flex-wrap: wrap lets items spill onto additional lines when they run out of room, the basis of responsive chip rows and card lists. What this generator deliberately does not emit are the per-item properties — flex-grow, flex-shrink, order, align-self — because those belong on the children, not the container; the container block here is the correct, complete foundation they build on. For two-dimensional layouts where rows and columns must align together, use grid instead — see the CSS Grid Generator.

Frequently asked questions

What is the difference between justify-content and align-items?

justify-content works on the main axis (the direction items are laid out), align-items on the cross axis. In a row, justify is horizontal spacing and align is vertical positioning. In a column they swap. Centering an item both ways takes justify-content: center plus align-items: center.

How do I center a box with flexbox?

Make its parent the flex container: display: flex; justify-content: center; align-items: center — and give the parent a height to centre within (for example min-height: 100vh for the viewport). The child needs no positioning, margins or transforms of its own.

space-between, space-around or space-evenly — which do I want?

space-between: first and last items flush with the edges, space only between items — navbars and card rows. space-evenly: identical gaps everywhere including the edges — evenly spread toolbars. space-around: each item gets equal space around it, which visually halves the edge gaps — rarely the intended look, and the usual reason a design looks “almost” evenly spaced.

Why are my flex items all the same height?

Because align-items defaults to stretch: items without an explicit height (in a row) are stretched to match the tallest item on the line. Set align-items: flex-start, center or flex-end in this generator if you want items to keep their natural heights.

📦 Embed this tool on your site

<iframe src="https://verystep.com/embed/css-flexbox-generator/" title="CSS Flexbox Generator" width="100%" height="520" loading="lazy" style="border:0"></iframe>

Free to use. The embed shows a small "Powered by Verystep" link.

First time embedding? Read the step-by-step guide →

More free tools