CSS Flexbox Cheat Sheet

A reference for CSS Flexbox, the container properties (flex-direction, justify-content, align-items, gap) and the item properties (flex, flex-grow, align-self), with what each value does.

A reference to CSS Flexbox, the one-dimensional layout model. Set properties on the flex container to control the row or column, and on the flex items to control how each one sizes and aligns. Click any value to copy it.

Container properties

PropertyWhat it does
display: flexTurn an element into a flex container
flex-direction: rowLay items out left to right (row-reverse, column, column-reverse)
justify-content: centerAlign items on the main axis (flex-start, flex-end, space-between, space-around, space-evenly)
align-items: centerAlign items on the cross axis (stretch, flex-start, flex-end, baseline)
flex-wrap: wrapLet items wrap onto new lines (nowrap, wrap-reverse)
align-content: centerAlign wrapped lines when there is extra space
gap: 1remSpace between items (row-gap / column-gap)

Item properties

PropertyWhat it does
flex: 1Shorthand for grow, shrink, and basis (1 1 0)
flex-grow: 1How much spare space an item takes (0 = no grow)
flex-shrink: 1How much an item shrinks when space is tight
flex-basis: 200pxThe starting size before grow/shrink apply
align-self: flex-endOverride the container's align-items for one item
order: 2Change source order (default 0)

Tip: to center a single child both ways, on the parent use display: flex, justify-content: center, and align-items: center. Remember justify-content runs along the row and align-items runs across it.

What this does

A CSS Flexbox cheat sheet lists the container properties like flex-direction, justify-content, align-items, and gap, and the item properties like flex and align-self, with what each value does.

How to use it

  1. Browse by property.
  2. Find the value you need.
  3. Copy it with one tap.
  4. Paste it into your stylesheet.

Example

display: flex; justify-content: center; align-items: center; centers a child both ways.

Sources & methodology

Last updated .

Frequently asked questions

Flexbox or grid — when do I use which?

Use Flexbox for one-dimensional layouts, a row or a column of items that wrap and size themselves. Use grid for two-dimensional layouts with rows and columns.

How do I center something with Flexbox?

On the parent, set display: flex, justify-content: center, and align-items: center. The first controls the main axis, the second the cross axis.

What does flex: 1 mean?

It is shorthand for flex: 1 1 0, so the item grows and shrinks and starts from a zero base size, making flex items share spare space equally.