Utilumo
LightDarkSystem

Updated June 29, 2026

CSS Flexbox cheat sheet

Flexbox lays out items in a single row or column and distributes space between them. Properties split into two groups: those you set on the flex container, and those you set on each flex item.

On the container

PropertyWhat it does
display: flexTurns an element into a flex container.
flex-direction: row | columnSets the main axis: horizontal or vertical.
flex-wrap: wrapAllows items to wrap onto multiple lines.
justify-content: space-betweenDistributes items along the main axis.
align-items: centerAligns items on the cross axis.
align-content: centerAligns wrapped lines on the cross axis.
gap: 1remSets spacing between items.

On the items

PropertyWhat it does
flex: 1Shorthand for grow, shrink, and basis; 1 means fill available space.
flex-grow: 1How much an item grows relative to siblings.
flex-shrink: 0Prevents an item from shrinking when space is tight.
flex-basis: 200pxThe item's starting size before growing or shrinking.
align-self: flex-endOverrides align-items for a single item.
order: 2Changes the visual order without moving the markup.

Common justify-content values

ValueEffect
flex-startPack items to the start.
centerCenter items on the main axis.
space-betweenFirst and last at the edges, equal gaps between.
space-aroundEqual space around each item.
space-evenlyEqual space between and at the ends.
Main axis vs cross axisjustify-content works along the main axis (set by flex-direction), while align-items works along the cross axis. Switching to flex-direction: column swaps which axis each one controls.

References

Questions

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

justify-content positions items along the main axis, while align-items positions them along the cross axis. Which direction each affects depends on flex-direction.

What does flex: 1 mean?

It is shorthand for flex-grow: 1, flex-shrink: 1, flex-basis: 0, which makes the item grow to share available space equally with other flex: 1 siblings.