flex-direction
Widely availableSince 201597% of users
Determines the orientation of flex items in a container, essentially choosing whether they form a horizontal row or a vertical column.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyClassic, with newer partsIt has worked everywhere since September 2015, and it keeps getting newer values.
Newer parts of flex-direction
column-reverseBaseline Sept 2020, Widely Mar 2023row-reverseBaseline Sept 2020, Widely Mar 2023
See how modern your own CSS is.Check your CSS →
Quick facts
- Initial value
row- Inherited
- No
- Applies to
- Flex containers
- Animation type
- discrete
Quick example
.container {
display: flex;
flex-direction: column;
} /* stacks items vertically */Syntax
flex-direction: row | row-reverse | column | column-reverserow- Default. Items are placed left to right in ltr languages, right to left in rtl. The main axis is horizontal.
row-reverse- Same as row but with the start and end points swapped. Items flow in the opposite direction of the writing mode.
column- Items stack vertically, top to bottom. The main axis becomes vertical.
column-reverse- Items stack vertically but from bottom to top. Useful for chat logs or feeds where newest items appear at the top visually.
Examples
Horizontal navigation bar
.nav {
display: flex;
flex-direction: row;
gap: 1rem;
}row is the default, but writing it makes intent clear when scanning code.
Stack on mobile, row on desktop
.card {
display: flex;
flex-direction: column;
}
@media (min-width: 640px) {
.card {
flex-direction: row;
}
}Changing flex-direction is a common responsive pattern: stack on small screens, switch to a row layout when there is room.
Reverse the visual order
.breadcrumb {
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
}row-reverse flips the visual order without changing the HTML. The first item in the markup appears on the right.
Common pitfalls
- Reverse directions do not change tab orderrow-reverse and column-reverse flip the visual display but leave keyboard tab order and screen reader order unchanged. This can create a confusing disconnect for keyboard and assistive technology users. Only use reverse when visual and reading order can diverge safely.
- align-items and justify-content swap axesWhen you switch from row to column, the main axis becomes vertical. justify-content now controls vertical alignment and align-items controls horizontal. The property names do not change, but the effective direction does.
- flex-wrap follows the main axisWith flex-direction: column, items wrap into new columns, not new rows. You need a fixed height on the container for column wrapping to produce new columns, otherwise everything stacks in one column.
See also
flex-wrapControls whether flex items stay on one line or wrap onto multiple lines.flex-flowShorthand for flex-direction and flex-wrap combined.justify-contentAligns items along the main axis, which is determined by flex-direction.align-itemsAligns items along the cross axis, perpendicular to flex-direction.
flex-direction browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
29+
22+
9+
12+Mobile
29+Android
22+Android
9+iOS