CSS flex-direction Property Explained
What the CSS flex-direction property does, with an example.
Published November 3, 2026
flex-direction sets the main axis of a flex container: row (default), row-reverse, column or column-reverse.
How it works
The main axis decides which direction items flow and which axis justify-content and align-items control. Switching to column swaps them.
Reverse values change visual order but not DOM order, which can hurt accessibility.
Values and effects
flex-direction: row; → left to right
flex-direction: row-reverse; → right to left
flex-direction: column; → top to bottom
flex-direction: column-reverse; → bottom to top
Practical examples
Vertical stack
.stack { display: flex; flex-direction: column; gap: 1rem; }Responsive
.wrap { display: flex; flex-direction: column; }
@media (min-width: 768px) { .wrap { flex-direction: row; } }Reverse order
.chat { display: flex; flex-direction: column-reverse; }Common mistakes
- Forgetting justify-content now works vertically in column mode.
- Using reverse values and breaking tab order.
- No height on a column container when expecting vertical centring.
Key takeaways
- flex-direction in one line: flex-direction sets the main axis of a flex container: row (default), row-reverse, column or column-reverse.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
How do axes change?
In column direction justify-content is vertical and align-items is horizontal.
Is flex-direction supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.