← Back to cheatsheets
CSS

CSS Flexbox

Complete flexbox reference. All container and item properties with values.

Container Properties

Command / PropertyDescription
display: flexEnable flex layout on the container
flex-direction: rowMain axis left to right (default)
flex-direction: row-reverseMain axis right to left
flex-direction: columnMain axis top to bottom
flex-direction: column-reverseMain axis bottom to top
flex-wrap: nowrapAll items on one line (default)
flex-wrap: wrapItems wrap to next line
flex-wrap: wrap-reverseItems wrap in reverse order
justify-content: flex-startPack items to the start (default)
justify-content: flex-endPack items to the end
justify-content: centerCenter items on main axis
justify-content: space-betweenEqual space between items
justify-content: space-aroundEqual space around items
justify-content: space-evenlyEqual space between and around items
align-items: stretchStretch items to fill container (default)
align-items: flex-startAlign items to cross axis start
align-items: flex-endAlign items to cross axis end
align-items: centerCenter items on cross axis
align-items: baselineAlign items by their text baseline
align-content: flex-startPack lines to the start
align-content: flex-endPack lines to the end
align-content: centerCenter lines in container
align-content: space-betweenEqual space between lines
align-content: space-aroundEqual space around lines
gap: 1remSet gap between flex items

Item Properties

Command / PropertyDescription
order: 0Control item order (default 0, lower = first)
flex-grow: 0How much item should grow (default 0)
flex-shrink: 1How much item should shrink (default 1)
flex-basis: autoDefault size before distributing space
flex: 1Shorthand: grow 1, shrink 1, basis 0%
flex: autoShorthand: grow 1, shrink 1, basis auto
flex: noneShorthand: grow 0, shrink 0, basis auto
align-self: autoUse container align-items value (default)
align-self: flex-startAlign this item to cross axis start
align-self: flex-endAlign this item to cross axis end
align-self: centerCenter this item on cross axis
align-self: stretchStretch this item to fill cross axis

Common Patterns

Command / PropertyDescription
display:flex; justify-content:center; align-items:centerPerfect centering (horizontal + vertical)
display:flex; flex-direction:column; min-height:100vhFull-height page layout
margin-left: autoPush item to the right (flex row)
flex: 1 on childMake one child fill remaining space
flex-wrap:wrap; gap:1remResponsive grid without media queries