CSS Flexbox Generator

A CSS flexbox generator writes display: flex code for you. Choose flex-direction, flex-wrap, justify-content, align-items and gap, see the items move live, and copy the CSS or Tailwind classes.

Set the flex direction, wrap mode, justify-content and align-items, adjust the gap and item count, see the layout update live, then copy the CSS or Tailwind classes ready for your project.

1
2
3
4

CSS

.container {
  display: flex;
  gap: 16px;
}

Tailwind classes

flex flex-row flex-nowrap justify-start items-stretch gap-4

How to use it

  1. Pick a direction (row, column, or reversed), set wrap mode, choose justify-content and align-items.
  2. Adjust the gap to space your items, and set how many items to generate (1 to 12).
  3. Watch the live preview update as you change each option, then copy the CSS or Tailwind classes.

Flexbox is ideal for one-dimensional layouts like nav bars, button groups, or card rows that wrap. For two-dimensional layouts with both columns and rows, use the CSS grid generator. When the flex layout should switch at a different screen width, use the CSS media query generator to write the matching breakpoint query.

Frequently asked questions

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

justify-content controls how flex items are positioned along the main axis (the row or column direction). align-items controls the alignment of items along the cross axis (perpendicular to the main axis). For a row layout, justify-content aligns items left-to-right, while align-items aligns them top-to-bottom.

When should I use flexbox instead of CSS grid?

Use flexbox for one-dimensional layouts like nav bars, button rows, or cards that wrap based on their content size. Use grid for two-dimensional layouts like card galleries, dashboards, or page sections with rows and columns. You can combine both: use grid for page structure and flexbox inside each cell. See the CSS grid generator for two-dimensional layouts.

What does align-content do and why does it need wrap?

align-content controls how multiple lines of flex items are positioned along the cross axis when there is extra space on the container’s cross size. It only has an effect when flex-wrap is enabled (wrap or wrap-reverse) and there are multiple lines. If items are all on one line (nowrap), align-content has no visible effect because there is no 'multi-line' behavior to align.

How does gap work in flexbox?

The gap property adds consistent spacing between flex items along both the main and cross axes. Unlike margin, gap doesn't affect the container’s size or create edge spacing, so it’s perfect for clean layouts. In the generator, the default gap of 16px provides comfortable breathing room between items, and you can adjust it from 0 to 200px.

What are the Tailwind equivalents for these flexbox properties?

In Tailwind, flex-direction maps to flex-row, flex-row-reverse, flex-col, or flex-col-reverse. flex-wrap maps to flex-wrap or flex-nowrap. justify-content maps to justify-start, justify-center, justify-end, justify-between, justify-around, or justify-evenly. align-items maps to items-stretch, items-start, items-center, items-end, or items-baseline. align-content maps to content-start, content-center, content-end, content-between, content-around, or content-stretch. gap maps to gap-1, gap-2, etc. for multiples of 4px, or gap-[10px] for other values.

More CSS generators

Color tools

Image tools

Image & SVG tools

Typography & units

More free tools

All free tools