Map Extract
Free tool

CSS flexbox generator

Flexbox lines things up in a row or a column: buttons in a header, logos in a strip, cards that wrap. Choose the settings and watch the preview boxes rearrange before you copy the CSS.

Runs in your browser. Nothing you enter is uploaded.

Building a flex container

  1. Pick the direction

    row lays items side by side, column stacks them; the reverse options flip the order.

  2. Spread the items

    justify-content places them along the direction: start, centre, end, or with space between, around or evenly.

  3. Align across

    align-items sets the other axis: stretch, start, centre, end or baseline. The preview boxes have different heights so you can see it.

  4. Wrap and space

    Choose flex-wrap and type a gap in pixels. Items in preview changes how many boxes are shown, up to 12.

  5. Copy the CSS

    The .container rule below updates live. Copy it or download flex.css.

Example: a header with a logo left and a button right

A small business site needs its logo on the left and a 'Request a quote' button on the right, vertically centred. With two items in the preview, set justify-content to space-between and align-items to center, keep the 12 px gap.

The generated rule is below. Apply it to the header element and the logo and button sit at opposite ends at any screen width.

Input
row, space-between, center, nowrap, gap 12, 2 items
Result
.container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 12px;
}

Common layouts and their settings

Layoutdirectionjustify-contentalign-itemswrap
Header: logo left, menu rightrowspace-betweencenternowrap
Centre one thing in a boxrowcentercenternowrap
Strip of client logosrowspace-evenlycenterwrap
Stacked form fieldscolumnflex-startstretchnowrap
Tags or chips that wraprowflex-startcenterwrap

Questions people ask

How do I centre something with flexbox?

Make the parent a flex container and set both justify-content and align-items to center. Here, choose center in both menus and copy the rule. The child is then centred horizontally and vertically, as long as the container has a height.

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

justify-content works along the direction the items flow, horizontally for a row. align-items works across it, vertically for a row. Switch flex-direction to column and the two swap roles, which the preview shows clearly.

Should I use gap or margins between flex items?

gap is simpler: it puts equal space between items and none on the outer edges, so there is nothing to undo on the first or last item. Current browsers all support gap with flexbox. Margins are only needed for unusual spacing on individual items.

Where your data goes

The preview and the CSS are generated in your browser. Nothing is uploaded.

Checked against the tool on

Top