CSS Flexbox Generator

Build a flexbox layout visually: set direction, wrapping, alignment and gap on the container, tune flex-grow, flex-shrink, flex-basis, align-self and order per item on a live preview, then copy clean CSS that only includes the properties you changed.

Container (.container)
Live previewClick an item to edit it
Items · editing item 1
Generated CSS
.container {
  display: flex;
}

Usage examples

Centering something both ways

Set justify-content and align-items to center on the container. The generated CSS is the classic three-line centering recipe: display: flex, justify-content: center and align-items: center.

Building a navigation bar

Put the logo and the link group in one flex row and choose justify-content: space-between to push them to opposite ends. Add a column-gap so the links never touch when the bar gets narrow.

Making equal-width columns

Select each item and set flex-grow to 1 with flex-basis 0. The tool outputs flex: 1, which gives every column the same width regardless of how much text it holds.

A card row that wraps on small screens

Turn on flex-wrap: wrap, add a gap, and give the items flex: 1 1 200px (grow 1, shrink 1, basis 200px). Cards stretch to fill each row and drop to the next line once they would get narrower than 200px.

Fixed sidebar next to fluid content

Give the sidebar grow 0, shrink 0 and basis 240px, which the tool writes as flex: 0 0 240px, and give the main area flex: 1. The sidebar keeps its width while the content takes the rest.

Quick reference

What each flex shorthand expands to

flexflex-growflex-shrinkflex-basis
flex: initial01auto
flex: auto11auto
flex: none00auto
flex: 1110%
flex: 2210%
flex: 0010%
flex: 1 0100%
flex: 2 2220%
flex: 1 1 0110
flex: 200px11200px
flex: 50%1150%
flex: 1 200px11200px
flex: 0 0 100px00100px
flex: 1 1 0px110px

How flex-grow and flex-shrink split a single line (empty items, no gap)

Container widthItems (grow shrink basis)Final widths
600px1 1 0px ; 1 1 0px ; 1 1 0px200px ; 200px ; 200px
600px1 1 0px ; 2 1 0px ; 1 1 0px150px ; 300px ; 150px
600px1 1 100px ; 2 1 100px ; 1 1 100px175px ; 250px ; 175px
600px0 1 200px ; 1 1 0px200px ; 400px
600px0.25 1 100px ; 0.25 1 100px200px ; 200px
500px0 1 300px ; 0 1 300px250px ; 250px
500px0 1 400px ; 0 2 200px350px ; 150px
500px0 0 300px ; 0 1 300px300px ; 200px

Start positions of three 100px items in a 600px row

justify-contentItem start positions
flex-start0px, 100px, 200px
flex-end300px, 400px, 500px
center150px, 250px, 350px
space-between0px, 250px, 500px
space-around50px, 250px, 450px
space-evenly75px, 250px, 425px

Frequently asked questions

What does flex: 1 actually mean?

flex: 1 is shorthand for flex-grow: 1, flex-shrink: 1, flex-basis: 0% (the spec says the omitted basis is 0; browsers report it as 0%). Because every item starts from zero and grows equally, items end up the same size. flex: auto (1 1 auto) instead starts from each item's content size and only shares the leftover space, so items with more content end up wider.

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

justify-content distributes items along the main axis, and align-items positions them on the cross axis. With flex-direction: row the main axis is horizontal; with column it is vertical, so the two properties swap their visual effect when you change direction.

space-between, space-around, or space-evenly?

space-between puts the first and last item flush with the edges and splits the rest between items. space-around gives each item equal space on both sides, so the edge gaps are half the gaps between items. space-evenly makes every gap, edges included, the same. For three 100px items in a 600px row they start at 0/250/500, 50/250/450, and 75/250/425 px respectively.

Why does align-content do nothing?

align-content only distributes space between flex lines, so it has no effect on a single-line container. It needs flex-wrap: wrap (or wrap-reverse) and enough items to actually wrap onto several lines. The generator leaves align-content out of the CSS while flex-wrap is nowrap.

How is the space from flex-grow calculated?

The browser subtracts every item's flex-basis (and the gaps) from the container size, then shares the remaining free space in proportion to flex-grow. Three items with basis 100px and grow 1, 2, 1 in a 600px row get 75, 150 and 75px extra, ending at 175, 250 and 175px. If the grow values add up to less than 1, only that fraction of the free space is handed out.

Why won't my flex item shrink below its content?

Flex items have min-width: auto (min-height: auto in a column) by default, which stops them from shrinking below their minimum content size, such as a long word or URL. Add min-width: 0 (or overflow: hidden) to that item to let it shrink, for example so text-overflow: ellipsis can work.

Is the gap property safe to use with flexbox?

Yes, in current browsers. Flexbox gap has been supported since Chrome 84, Firefox 63 and Safari 14.1. Only very old browsers ignore it, in which case items simply sit next to each other without the spacing.