coderef

Flexbox

Visual cheat sheet for CSS Flexible Box Layout — every property with live previews you can copy. The dashed box is the flex container.

Click any example to copy its CSS.

Flex container

display

flex lays children out in a row. inline-flex does the same, but the container only takes the width it needs.

flex-direction

Sets the main axis — the direction items flow in.

flex-wrap

nowrap squeezes every item onto one line; wrap moves items that don't fit onto new lines.

flex-flow

Shorthand for flex-direction and flex-wrap.

justify-content

Distributes items and free space along the main axis.

align-items

Aligns items on the cross axis. Items here have different heights so you can see the difference.

align-content

Distributes wrapped lines on the cross axis (only matters when items wrap).

gap

Space between items and between wrapped lines — never at the edges.

Flex items

order

Moves an item earlier or later than its position in the HTML. Default is 0.

flex-grow

How much of the free space an item takes. Here the other items have flex-grow: 1.

flex-shrink

How much an item gives up when there isn't enough room. Each item here wants 50% of the width.

flex-basis

The item's starting size on the main axis, before free space is shared out.

flex

Shorthand for flex-grow, flex-shrink and flex-basis. The other items here have flex: 1.

align-self

Overrides align-items for one item. The container here uses align-items: flex-start.

margin: auto

An auto margin soaks up all free space on that side — the easy way to push items apart.