flexbox

flex-direction

Sets the main axis of a flex container, deciding whether items lay out horizontally or vertically. It also determines which direction items are reversed if needed.

flex-direction: row | row-reverse | column | column-reverse

Common values

Value Effect
row Default; items flow horizontally in writing direction
row-reverse Items flow horizontally in reverse
column Items stack vertically top to bottom
column-reverse Items stack vertically bottom to top

Examples

.nav { display: flex; flex-direction: row; }

Horizontal navigation bar

.stack { display: flex; flex-direction: column; gap: 1rem; }

Vertical stack of elements with spacing

.footer { display: flex; flex-direction: row-reverse; }

Items appear right-to-left

Gotcha

Switching to column swaps the meaning of justify-content and align-items because the main axis rotates.

Related properties

← All CSS properties · CSS selectors · Grid vs Flexbox