CSS Flexbox Generator

Build CSS Flexbox layouts visually. Configure flex direction, wrap, justify-content, align-items, and gap with a live preview. Free online tool.

  • Runs in your browser
  • Your data never leaves your browser
  • Free · No Sign-Up
Choose row, row-reverse, column or column-reverse. The preview and CSS update immediately.
Choose nowrap, wrap or wrap-reverse to control whether items form additional lines.
Enter a CSS gap. One value sets both gaps; two values are row gap then column gap. Empty uses 1rem, and values are copied without validation.
Set 1–8 preview items. This changes the number of boxes; the exported rule contains container properties only.
Alignment
Choose how items share space along the main axis set by flex-direction. The initial selection is normal.
Choose the item alignment on the cross axis. The initial selection is normal. This sets the container property, not individual items.
Choose how wrapped lines align on the cross axis. This property has no effect with nowrap. The initial selection is normal.
Copy the complete .container rule with seven declarations. Ctrl/⌘+L clears the gap text, CSS and preview while keeping selects and item count. Retry a failed copy or select the CSS manually.

Read the full guide CSS Flexbox Explained: Axes, the flex Shorthand, min-width: auto and align-content
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.

Understanding the Generated CSS

The generator outputs a .container rule with seven declarations: display: flex, flex-direction, flex-wrap, justify-content, align-items, align-content, and gap. Paste it into your stylesheet and rename .container to your own class name. Every property is written out, even at its default, so you can delete the lines you do not need. The drop-downs start at the CSS initial values: row, nowrap, and normal for justify-content, align-items and align-content. In a flex container normal stretches items and wrapped lines on the cross axis and packs items at the start of the main axis (CSS Box Alignment Level 3). Those three lines therefore behave as if they were not written. The gap: 1rem line is different: the initial gap of a flex container is normal, which is 0, so the default rule adds 1rem between the items. Delete that line if you do not want the space. The default output is:

.container {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: normal;
  align-items: normal;
  align-content: normal;
  gap: 1rem;
}

Example: a Navigation Bar

Keep row and nowrap, set justify-content to space-between, align-items to center and gap to 16px:

.container {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  align-content: normal;
  gap: 16px;
}

Take a 600px container with three 100px items. The gaps use 32px, so 268px of free space is left for justify-content to share out. With space-between the items start at 0, 250 and 500px: the first and last items touch the edges and the free space goes between them, on top of the gaps. With space-around they start at 44.67, 250 and 455.33px (half-size space at the ends), and with space-evenly at 67, 250 and 433px (equal space everywhere). The align-content line does nothing here because the container does not wrap; you can delete it.

Example: Tags That Wrap

Set flex-wrap to wrap, align-items to flex-start, align-content to center, and gap to 8px 12px:

.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: normal;
  align-items: flex-start;
  align-content: center;
  gap: 8px 12px;
}

Here align-content matters. In a 200px-tall container whose three 40px items fit on one line, the line moved down to 80px from the top. The same settings with nowrap left the items at the top, because a single-line flex container ignores align-content (CSS Flexbox Level 1 §8.4).

Limits and Common Surprises

  • Container properties only. There are no controls for the items: flex-grow, flex-shrink, flex-basis, order and align-self must be added by hand. A common next step is flex: 1 on the item that should take the remaining space.
  • Long words do not shrink. A flex item’s minimum width is auto, its longest unbreakable content. In a 300px row, an item holding a long URL stayed 684px wide and overflowed. Add min-width: 0 (plus overflow-wrap: anywhere or text-overflow) to that item.
  • Missing values. justify-content has no stretch or start/end, and align-content has no space-evenly; type them into the copied CSS if you need them.
  • Reverse directions change only the visual order. Keyboard focus and screen readers still follow the HTML order.
  • The gap field is not validated: an invalid value is copied as written, and the browser drops it.

For layouts that need rows and columns at once, use the CSS grid generator.

Flexbox vs Grid

Use Flexbox when you have a one-dimensional layout — items along a single row or column. Use CSS Grid when you need two-dimensional control over both rows and columns simultaneously. In practice, Flexbox excels at component-level layout (navigation, button groups, form rows), while Grid is better for page-level structure.

FAQ

What is CSS Flexbox?

CSS Flexbox (Flexible Box Layout) is a one-dimensional layout model that distributes space along a single axis — either a row or a column. It is ideal for navigation bars, toolbars, card rows, centering elements, and any UI that needs items arranged along a single direction with flexible spacing.

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

justify-content controls alignment along the main axis (the direction defined by flex-direction). align-items controls alignment along the cross axis (perpendicular to the main axis). For a row flex container: justify-content aligns horizontally and align-items aligns vertically.

When should I use flex-wrap?

By default flex-wrap is nowrap — all items stay on one line and shrink if they can. Set flex-wrap: wrap to let items move onto further lines when they cannot fit. This is useful for responsive card rows or tag lists that should reflow at smaller widths.

What does align-content do?

align-content distributes the flex lines along the cross axis. It works only when flex-wrap is wrap or wrap-reverse. Such a container counts as multi-line even when every item fits on one line, so align-content then moves that single line; with nowrap it has no effect.

What is the gap property in Flexbox?

gap (shorthand for row-gap and column-gap) sets the space between flex items without adding margin to the outer edges of the container. It started as a Grid property; in flex containers it works in Chrome 84, Firefox 63 and Safari 14.1 and later.

Are my settings sent anywhere or saved?

No. The CSS is built in your browser tab, and the selected values, gap and item count are not sent to a server or written to browser storage. The page's analytics records a usage event with the tool name and the action (generate or copy), not your settings.