X

Headline

This is an important message requiring you to make a choice if you're based in the EU.

CSS flex-direction Property

The flex-direction property defines the main axis of a flex container and sets the order in which flex items appear.

The flex-direction property is one of the CSS3 properties.

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

Flex items can be displayed:

  • horizontally along the row from left to right (flex-direction:row) or right to left (flex-direction:row-reverse)
  • vertically from top to bottom (flex-direction:column) or from bottom to top (flex-direction)

If there are no flexible items, the flex-direction property has no effect.

Initial Value row
Applies to Flex containers.
Inherited No.
Animatable No.
Version CSS3
DOM Syntax object.style.flexDirection = "row-reverse";

Syntax

flex-direction: row | row-reverse | column | column-reverse | initial | inherit;

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style> 
      .example  {
      width: 350px;
      height: 350px;
      border: 1px solid #c3c3c3;
      display: flex;
      flex-direction: column-reverse; 
      }
      .example  div {
      width: 70px;
      height: 70px;
      }
    </style>
  </head>
  <body>
    <h2>Flex-direction property example</h2>
    <div class="example">
      <div style="background-color: #8ebf42;">A</div>
      <div style="background-color: #1c87c9;">B</div>
      <div style="background-color: #eee;">C</div>
      <div style="background-color: #666;">F</div>
    </div>
  </body>
</html>

In the following example "row-reverse" value is used where items are displayed horizontally as a row from right to left.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style> 
      .example  {
      width: 350px;
      height: 350px;
      border: 1px solid #c3c3c3;
      display: flex;
      flex-direction: row-reverse; 
      }
      .example  div {
      width: 70px;
      height: 70px;
      }
    </style>
  </head>
  <body>
    <h2>Flex-direction property example</h2>
    <div class="example">
      <div style="background-color: #8ebf42;">A</div>
      <div style="background-color: #1c87c9;">B</div>
      <div style="background-color: #eee;">C</div>
      <div style="background-color: #666;">F</div>
    </div>
  </body>
</html>

Values

Value Description
row Items are displayed horizontally as a row. This is the default value of this property.
row-reverse Items are displayed in a row in a reverse order (from right to left).
column Items are displayed vertically from top to bottom.
column-reverse Items are displayed vertically from bottom to top.
initial The property uses its default value.
inherit The property inherits value from its parents element.

Browser support

29.0+
21-28 -webkit-
12.0+ 28.0+ 9.0+
6.1-8.0 -webkit-
12.1+


Do you find this helpful?

Related articles