Grow your CSS skills. Land your dream job.

flex-direction

Last updated on:

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).

Comments

  1. Permalink to comment#

    Hi, I recently got stuck with the flexible box model, because I couldn’t figure out how to get flex-direction: column to work on pre-6.1 safari. -webkit-flex-direction: column is not supported, and neither is the shorthand -webkit-flex-flow: column wrap.

    I discovered here that in order to achieve the column direction with the old box-* syntax in webkit browsers we have to use:
    -webkit-box-orient: vertical.

    I had a hard time finding this info, so I thought I’d leave a comment to help anyone out who is trying to achieve true cross-browser flex support. Anyone else encounter this?

  2. Permalink to comment#

    Thanks, Colin! I was trying to figure out what Safari had a problem with all day when I found your comment.

  3. Kalle
    Permalink to comment#

    Hi

    Maybe i´m late discovering this, Colin´s findings were just the right medicine for oldtimer Safari (3 and i belive up to 5.1.7 or so).

    Thanks a lot

Leave a Comment

Current day month ye@r *

*May or may not contain any actual "CSS" or "Tricks".