Home / CSS Almanac / Properties / F / flex-direction

flex-direction

The flex-direction property is a sub-property of the Flexible Box Layout module.

It establishes the main-axis, thus defining the direction flex items are placed in the flex container.

Reminder: the main axis of a flex container is the primary axis along which flex items are laid out. Beware, it is not necessarily horizontal; it depends on the flex-direction property.

The flex-direction property accepts 4 different values:

  • row (default): same as text direction
  • row-reverse: opposite to text direction
  • column: same as row but top to bottom
  • column-reverse: same as row-reverse top to bottom

Note that row and row-reverse are affected by the directionality of the flex container. If its text direction is ltr, row represents the horizontal axis oriented from left to right, and row-reverse from right to left; if the direction is rtl, it's the opposite.

Syntax

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

.flex-container {
  flex-direction: row;
}

Demo

In the following demo:

  • Red list is set to row
  • Yellow list is set to row-reverse
  • Blue list is set to column
  • Green list is set to column-reverse

Note: The text direction hasn't been edited.

Check out this Pen!

So basically, you will use row in most cases, or column under certain circumstancies. Otherwise, it is pretty uncommon to reverse direction order.

Related Properties

Other Resources

Browser Support

  • (modern) means the recent syntax from the specification (e.g. display: flex;)
  • (hybrid) means an odd unofficial syntax from 2011 (e.g. display: flexbox;)
  • (old) means the old syntax from 2009 (e.g. display: box;)
Chrome Safari Firefox Opera IE Android iOS
21+ (modern)
20- (old)
3.1+ (old) 2-21 (old)
22+ (new)
12.1+ (modern) 10+ (hybrid) 2.1+ (old) 3.2+ (old)

Blackberry browser 10+ supports the new syntax.

For more informations about how to mix syntaxes in order to get the best browser support, please refer to this article (CSS-Tricks) or this article (DevOpera).