CSS Reference ยท Flexbox
The flex-direction property
Reference for the CSS flex-direction property: row, row-reverse, column and column-reverse, how they set the main axis, and the catch of reversing.
The flex-direction property chooses the main axis of a flex container, and therefore the direction in which its items are placed. The cross axis is always the other one. Nearly every other flexbox property (justify-content, flex-grow, flex-basis) is defined in terms of this axis.
The default is row: items run in the direction text runs in the current writing mode, which is left to right in English.
CSS
.toolbar { display: flex; flex-direction: row; } .sidebar { display: flex; flex-direction: column; }
Try it
Syntax
CSS
flex-direction: row | row-reverse | column | column-reverse;
- Initial value:
row - Applies to: flex containers
- Inherited: no
- Animatable: no (discrete)
- Computed value: as specified
Values
| Value | Description |
|---|---|
row |
Main axis runs along the inline direction. Items start at the start edge: left in left-to-right text, right in right-to-left text. |
row-reverse |
Same axis, but items start at the opposite end and are laid out backwards. |
column |
Main axis runs along the block direction, top to bottom in horizontal writing modes. |
column-reverse |
Same axis as column, items start at the bottom and go up. |
Usage notes
rowfollows the writing direction. In an Arabic or Hebrew page (dir="rtl"),rowstarts at the right. The same CSS works for both languages.- The axes swap with the direction. In
column,justify-contentworks vertically andalign-itemsworks horizontally. This is the most common source of confusion. - Columns need height to share. A column container is as tall as its content unless you give it a height, so there is nothing for
flex-growto distribute. - Reversing is only visual. Screen readers, keyboard focus and text selection follow the HTML order. Do not use
row-reverseorcolumn-reverseto put content in an order that matters. Reorder the HTML instead. - Start/end flip with reverse. In
row-reverse,justify-content: flex-startputs items on the right (in left-to-right text). - Responsive layouts. Switching between
columnandrowwith a media query is the standard way to stack items on small screens. - Use
flex-flowto set direction and wrapping together.
Browser support
Supported in every browser.