RevealTheme logo

CSS Flexbox Generator

Build CSS flexbox layouts visually. See the result live as you adjust direction, alignment, wrapping, and gap.

1
2
3
4
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
gap: 8px;

How to use this tool

  1. 1

    Pick values from the four dropdowns: flex-direction, justify-content, align-items, and flex-wrap.

  2. 2

    Drag the gap slider to set the spacing between items, from 0 to 40 pixels.

  3. 3

    Watch the live preview of four numbered boxes update instantly to reflect each change.

  4. 4

    Click 'Copy CSS' to copy the generated declaration block, then paste it onto your own flex container.

What is the CSS Flexbox layout model?

Flexbox (the CSS Flexible Box Layout) is a one-dimensional layout model for distributing items along a single row or column and aligning them within their container. You opt in by setting display: flex on a parent; its direct children become flex items. flex-direction picks the main axis (row or column, optionally reversed). justify-content positions items along that main axis, with options like flex-start, center, space-between, and space-evenly. align-items aligns them on the perpendicular cross axis (stretch, center, baseline, and the flex-start/flex-end edges). flex-wrap decides whether items overflow onto new lines instead of shrinking. gap adds consistent spacing between items without margin hacks. This generator exposes exactly these five container-level properties plus display: flex, and nothing more. It does not control item-level properties such as flex-grow, flex-shrink, flex-basis, the flex shorthand, order, or align-self, so uneven sizing and reordering of individual children are not covered here and must be added by hand. The output is a plain declaration block you apply to your container; the children are yours. For two-dimensional grids of rows and columns, reach for CSS Grid instead.

Common use cases

  • Aligning a horizontal navigation bar so links sit at flex-start and a logo or button pushes to flex-end with space-between.

  • Centering a single element both horizontally and vertically using justify-content: center and align-items: center.

  • Spacing a row of buttons or tags evenly with a fixed gap instead of fragile margins.

  • Stacking form fields vertically by switching flex-direction to column while keeping consistent gap spacing.

  • Letting a row of cards wrap onto new lines on narrow screens with flex-wrap: wrap.

  • Learning how justify-content and align-items behave by toggling values and watching the live preview before committing the code.

Frequently asked questions

When should I use Flexbox instead of CSS Grid?
Use flexbox for one-dimensional layouts where content flows in a single direction, such as a navbar, a toolbar, or a row of buttons. Use CSS Grid for two-dimensional layouts that need explicit rows and columns at once, such as a responsive gallery of cards.
Does this tool let me set flex-grow, flex-basis, or order on individual items?
No. It only generates container-level properties (display, flex-direction, justify-content, align-items, flex-wrap, and gap). Item-level properties like flex-grow, flex-shrink, flex-basis, the flex shorthand, order, and align-self are not exposed, so you would add those manually to specific children after copying the base CSS.
What units does the gap control use?
The gap slider produces a single pixel value between 0 and 40, applied to both row and column spacing. If you need rem, percentage, or separate row-gap and column-gap values, edit the copied gap declaration by hand.
Can I change the number of preview items?
No. The preview always shows four fixed boxes purely to illustrate alignment and wrapping. They are not part of the generated CSS, which only describes the container; your real items replace them in your own markup.
Why isn't the Copy button working?
Copying uses the browser clipboard API, which only runs in a secure context. It works on HTTPS pages and on localhost, but may be blocked on plain HTTP or in older browsers. If it fails, you can select the CSS text in the preview block and copy it manually.
Is my data uploaded anywhere?
No. Everything runs entirely in your browser. Your selections and the generated CSS never leave your device, and there is no server call. Even copying only writes to your local clipboard.
Does the generated CSS work in all modern browsers?
Yes. display: flex and these properties are supported across all current browsers. The gap property on flex containers is also widely supported in modern versions; very old browsers may ignore gap, in which case margins are the fallback.

Related tools