elefcode
← All cheat sheets

CSS

CSS Flexbox Cheat Sheet — Properties Reference

Flexbox properties split into two groups — those you set on the container, and those you set on the items. This reference covers both.

Put it into practice with the matching tool.

Try the Flexbox playground

Advertisement

Container properties

display: flexMake the element a flex container
flex-direction: row | columnMain axis direction (also row-reverse, column-reverse)
justify-content: centerAlign items along the main axis
justify-content: space-betweenEven gaps, no space at the ends
align-items: centerAlign items along the cross axis
align-items: stretchItems fill the cross axis (default)
flex-wrap: wrapAllow items to wrap onto multiple lines
align-content: centerAlign wrapped lines (only with wrapping)
gap: 12pxSpace between items

Item properties

flex: 1Grow to fill available space (shorthand)
flex-grow: 1How much the item grows relative to siblings
flex-shrink: 0Prevent the item from shrinking
flex-basis: 200pxStarting size before growing/shrinking
align-self: flex-endOverride align-items for one item
order: -1Change visual order without changing the HTML

Common recipes

display:flex; justify-content:center; align-items:centerPerfectly center a child both ways
display:flex; justify-content:space-betweenNavbar — logo left, links right
margin-left: autoPush one item to the far right
display:flex; flex-wrap:wrap; gap:16pxResponsive wrapping card row
flex-direction: column; min-height: 100vhSticky footer layout

More cheat sheets