CSS Flexbox Generator

Visually configure every flexbox property with a live preview. Pick a preset to start fast, then tweak container and per-item settings — copy the generated CSS or HTML when you're done.

Presets:

display

Block-level vs inline-level flex container.

flex-direction

Sets the main axis and item flow direction.

flex-wrap

Whether items wrap onto new lines when they overflow.

justify-content

Distributes items and free space along the main axis.

align-items

Aligns items along the cross axis within a flex line.

align-content

Distributes space between flex lines (only when wrapping).

gap

Space between flex items. Applies to both row and column gaps.

Items

Click a number to select. Click × to remove. Max 10 items.

Editing item

align-self

flex-grow

How much this item grows relative to siblings when extra space is available.

flex-shrink

How much this item shrinks when the container is too small.

flex-basis

Initial size before flex-grow/shrink applies.

Shorthand

width

px

0 = not set

height

px

0 = not set

order

Visual order (not DOM order). Negative values move item earlier.

Live Preview
Main axis: Cross axis: display:

Container properties

display
flex | inline-flex
flex-direction
row | row-reverse | column | column-reverse
flex-wrap
nowrap | wrap | wrap-reverse
justify-content
flex-start | flex-end | center | space-between | space-around | space-evenly
align-items
stretch | flex-start | flex-end | center | baseline
align-content
stretch | flex-start | flex-end | center | space-between | space-around
gap
Shorthand for row-gap + column-gap

Item properties

flex-grow
Growth factor (default: 0)
flex-shrink
Shrink factor (default: 1)
flex-basis
Initial size before grow/shrink (default: auto)
flex
Shorthand: grow shrink basis
align-self
Override align-items for this item
order
Visual order (default: 0)

Flex shorthand cheatsheet

flex: 1
= flex: 1 1 0% (grow + shrink)
flex: auto
= flex: 1 1 auto
flex: none
= flex: 0 0 auto (rigid)
flex: 0 0 200px
Fixed 200px, no grow/shrink

Common patterns

Perfect centering
jc: center; ai: center
Equal columns
each: flex: 1 1 0
Fixed sidebar
sidebar: flex: 0 0 Npx; main: flex: 1
Push last item
last child: margin-left: auto

Frequently asked questions

justify-content controls alignment along the main axis (the direction set by flex-direction), while align-items controls alignment on the cross axis (perpendicular to the main axis). In a row layout, justify-content is horizontal and align-items is vertical — switch to column and they swap.
flex: 1 is shorthand for flex: 1 1 0% — the item can grow (flex-grow: 1), shrink (flex-shrink: 1), and starts from a calculated base size of zero (flex-basis: 0%). This forces all siblings with flex: 1 to share available space equally, regardless of their content size. Two other common values: flex: auto expands to flex: 1 1 auto (grows and shrinks but respects natural content size), and flex: none expands to flex: 0 0 auto (rigid — no growing or shrinking).
flex-basis sets the starting size of a flex item before remaining space is distributed according to flex-grow and flex-shrink. Unlike width, it respects the flex axis — in a column layout it behaves like height. Setting flex-basis: 0 with flex-grow: 1 makes all items share space equally regardless of content size.
To center a div with flexbox, set the parent container to display: flex, then add align-items: center to center vertically and justify-content: center to center horizontally. Use both together to center a div in the middle of its container — this is the standard CSS centering solution. Try the Centered preset in this generator to see it instantly.
They solve different problems. Flexbox is one-dimensional — it lays items out in a single row or column and excels at aligning content within a component (navigation bars, button groups, card footers). CSS Grid is two-dimensional — it controls rows and columns simultaneously and is better for overall page structure and grid-based designs. Use them together: Grid for the page, Flexbox for the components inside it.
Give each column flex: 1 (shorthand for flex: 1 1 0). Setting flex-basis to 0 forces all items to start from zero and divide available space equally, regardless of how much content each column contains. For three equal columns with a gap, set the container to display: flex; gap: 1rem and each child to flex: 1. Use the Equal Cols preset in this generator to apply this pattern instantly.
The most common cause is min-width: auto — the browser default for flex items — which prevents items from shrinking below their natural content size. Add min-width: 0 to the overflowing item to allow it to shrink correctly. Images inside flex items often need max-width: 100% for the same reason. In a column layout, min-height: 0 has the same effect on the cross axis.
Yes — flexbox is fully supported in every modern browser (Chrome, Firefox, Safari, Edge) without vendor prefixes. It has been baseline available since 2017. You do not need a polyfill or fallback for any actively supported browser. Internet Explorer 11 had a partial, buggy implementation, but IE11 reached end-of-life in 2022 and is not a concern for new projects.