Home/Tools/Layout/CSS Flexbox Generator
Layout · Generator

CSS Flexbox Generator

Visually build flexible CSS Flexbox layouts — set alignment, justify content, and direction with live preview. Copy production-ready CSS instantly. Free, no sign-up.

Container Properties

16px

Items

4

Preview

1
2
3
4
Generated CSS
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
gap: 16px;
100%
Free, no
sign-up needed
0
Code written
by hand
85+
CSS tools
in one place
<1s
Copy-ready
CSS instantly
What is this

What is the CSS Flexbox Generator?

Visually set flex container and item properties. Adjust direction, alignment, wrapping, and order with live preview, then copy production-ready CSS.

Everything runs locally in your browser. Adjust the controls above, preview instantly, and copy clean, production-ready CSS — no account, no upload.

How to use

Using the CSS Flexbox Generator

Everything lives in the panel at the top of this page. There is nothing to install — it all runs right here in your browser.

1

Set the container properties

Choose flex-direction, justify-content, align-items, and flex-wrap from the visual controls. The preview updates in real time.

2

Configure individual items

Select any item in the preview to set its flex-grow, flex-shrink, flex-basis, align-self, and order values independently.

3

Copy the CSS

Click Copy CSS to grab the container and item rules. Paste them into your stylesheet.

The output

What the generated code looks like

Clean, production-ready CSS — no vendor bloat, no unnecessary declarations.

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

.flex-item {
  flex: 1 1 200px; /* grow, shrink, basis */
}

Apply .flex-container to the parent element. Each direct child becomes a flex item automatically.

Copy & paste

Ready-to-use CSS patterns

Drop any of these straight into your project — no modifications needed.

Centered content

Center any element horizontally and vertically inside its parent.

styles.css
.centered {
  display: flex;
  justify-content: center;
  align-items: center;
}

Also works with min-height: 100vh for full-page centering.

Navigation bar

Logo left, links right - the classic nav layout.

styles.css
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 60px;
}

Add flex-wrap: wrap and a media query for mobile.

Card row with equal heights

Cards stretch to equal height automatically.

styles.css
.card-row {
  display: flex;
  gap: 20px;
  align-items: stretch;
}
.card-row > * {
  flex: 1;
}

align-items: stretch is the default - no need to set it explicitly.

Sticky footer layout

Footer stays at the bottom even when content is short.

styles.css
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.page-content {
  flex: 1;
}

flex: 1 on content makes it expand to fill available space.

Reference

Flexbox properties quick reference

Container properties control the layout. Item properties override for individual children.

Container properties

PropertyCommon valuesWhat it does
flex-directionrow | columnSets the main axis direction
justify-contentflex-start | center | space-between | space-aroundAligns items on the main axis
align-itemsstretch | center | flex-start | flex-end | baselineAligns items on the cross axis
flex-wrapnowrap | wrap | wrap-reverseControls whether items wrap to new lines
gappx / rem valueSpace between items (replaces margin hacks)
gap works on flex containers in Chrome 84+, Firefox 63+, Safari 14.1+. For older browsers, use margin on items with a negative margin on the container.

Item properties

PropertyDefaultWhat it does
flex-grow0Whether item grows to fill available space
flex-shrink1Whether item shrinks when space is tight
flex-basisautoInitial size before grow/shrink is applied
align-selfautoOverride align-items for this item only
order0Visual order (does not affect DOM order)
Common mistakes & fixes

Common mistakes & how to fix them

A few habits trip people up. Here is what to watch for — and the exact fix.

Using margin for spacing instead of gap

Adding margin-right to items creates extra space at the end of each row and makes responsive wrapping behave unexpectedly.

Fix: Use gap on the flex container. It only adds space between items, never on the outside edges.

Forgetting flex-basis when using flex shorthand

flex: 1 sets grow:1, shrink:1, basis:0. flex: auto sets grow:1, shrink:1, basis:auto. These behave differently when content sizes vary.

Fix: Use the three-value shorthand explicitly: flex: 1 1 200px to be clear about minimum size.

Pro tips

Pro tips for better results

flex: 1 means grow equally, not equal widths

flex: 1 sets flex-grow:1 and flex-basis:0. Items with more content will still be wider because browsers calculate minimum content size. Use flex: 1 1 0 and overflow: hidden to force equal widths.

Use Flexbox for one-dimensional layouts

Flexbox excels at distributing items along a single axis - navigation bars, button groups, card rows. For two-dimensional page layouts (rows AND columns simultaneously), use CSS Grid instead.

align-content vs align-items

align-items controls single-line cross-axis alignment. align-content controls the spacing between multiple wrapped lines. align-content only has an effect when flex-wrap: wrap is set and there is more than one line.

order changes visual order, not DOM order

Using order for reordering can create a disconnect between visual and tab/focus order, which harms keyboard and screen reader accessibility. Use it only for supplementary reordering, not for main content flow.

FAQ

Frequently asked questions

Use Flexbox for one-dimensional layouts: a row of buttons, a navigation bar, a list of items. Use Grid when you need to control both rows and columns at once - page structure, card grids, dashboard layouts.
flex-wrap defaults to nowrap. Add flex-wrap: wrap to the container to allow items to break onto new lines when they run out of space.
On the parent: display: flex; justify-content: center; align-items: center. Add min-height: 100vh if you want it centred in the full viewport.
No. The generator runs in your browser. Nothing is sent to a server.

From the blog

Read more