Skip to content
📏

Flexbox Generator

Build flexbox containers visually and copy the CSS.

Runs in your browser

Updated

12px
16px
4

How the CSS is assembled

Five dropdowns cover flex-direction, flex-wrap, justify-content, align-items and align-content, preset to the CSS initial values: row, nowrap, flex-start, stretch and normal. Sliders add a gap (0 to 60, default 12 px), padding (0 to 60, default 16 px) and between 1 and 9 sample items, and a checkbox named Include a margin on each item is on by default. The output box always opens with display: flex on a .container rule and then appends only the properties that differ from their default, so a stock configuration emits nothing for direction or alignment. A positive gap or padding gets its own line, and the checked margin box adds a second rule giving .item a 4 pixel margin.

A worked example

Untouched, the generated text is exactly: .container with display: flex, gap: 12px and padding: 16px, followed by .item with margin: 4px. Changing the direction to column adds a single flex-direction: column line; picking space-between adds justify-content: space-between while everything else stays omitted. Dropping padding to zero removes its line entirely.

What the live preview does

A fixed-height 240 pixel white box hosts numbered indigo squares of 34 pixels with 6 pixel corners, inside a mirrored flex container that receives every control value. One convenience is baked in: when align-items is stretch and the direction starts with row, preview items also get flex: 1 so they visibly fill the line. Copy writes the textarea through the clipboard API.

Where it stops

  • Only container-level properties are generated; per-child flex-grow, flex-basis, order and align-self never appear.
  • The .item rule contains the margin and nothing else, so item sizing shown in the preview is not exported.
  • Omitting defaults keeps the CSS short but means the snippet relies on initial values if you later change one expectation.
  • No vendor prefixes or min-height workarounds are offered for older browsers.

Questions people ask

Why is there no justify-content in the output?

The selector is still on flex-start, the browser default, and the generator only writes non-default properties to keep the snippet minimal.

Does align-content do anything with one row?

Only when wrapping creates multiple lines; with nowrap it has no visible effect in the preview either.

For two-dimensional layouts reach for the CSS grid generator, and tune outer spacing with the padding and margin generator.