flex-direction CSS property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

The flex-direction CSS property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed).

Try it

flex-direction: row;
flex-direction: row-reverse;
flex-direction: column;
flex-direction: column-reverse;
<section class="default-example" id="default-example">
  <div class="transition-all" id="example-element">
    <div>Item One</div>
    <div>Item Two</div>
    <div>Item Three</div>
  </div>
</section>
#example-element {
  border: 1px solid #c5c5c5;
  width: 80%;
  display: flex;
}

#example-element > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  width: 60px;
  margin: 10px;
}

Note that the values row and row-reverse are affected by the directionality of the flex container. If its dir attribute is ltr, row represents the horizontal axis oriented from the left to the right, and row-reverse from the right to the left; if the dir attribute is rtl, row represents the axis oriented from the right to the left, and row-reverse from the left to the right.

Syntax

css
/* The direction text is laid out in a line */
flex-direction: row;

/* Like <row>, but reversed */
flex-direction: row-reverse;

/* The direction in which lines of text are stacked */
flex-direction: column;

/* Like <column>, but reversed */
flex-direction: column-reverse;

/* Global values */
flex-direction: inherit;
flex-direction: initial;
flex-direction: revert;
flex-direction: revert-layer;
flex-direction: unset;

Values

The following values are accepted:

row

The flex container's main-axis is defined to be the same as the text direction. The main-start and main-end points are the same as the content direction.

row-reverse

Behaves the same as row but the main-start and main-end points are opposite to the content direction.

column

The flex container's main-axis is the same as the block-axis. The main-start and main-end points are the same as the before and after points of the writing-mode.

column-reverse

Behaves the same as column but the main-start and main-end are opposite to the content direction.

Accessibility

Using the flex-direction property with values of row-reverse or column-reverse will create a disconnect between the visual presentation of content and DOM order. This will adversely affect users experiencing low vision navigating with the aid of assistive technology such as a screen reader. If the visual (CSS) order is important, then screen reader users will not have access to the correct reading order.

Formal definition

Initial valuerow
Applies toflex containers
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

flex-direction = 
row |
row-reverse |
column |
column-reverse

Examples

Reversing flex container columns and rows

HTML

html
<h4>This is a Column-Reverse</h4>
<div id="col-rev" class="content">
  <div class="box red">A</div>
  <div class="box lightblue">B</div>
  <div class="box yellow">C</div>
</div>
<h4>This is a Row-Reverse</h4>
<div id="row-rev" class="content">
  <div class="box red">A</div>
  <div class="box lightblue">B</div>
  <div class="box yellow">C</div>
</div>

CSS

css
.content {
  width: 200px;
  height: 200px;
  border: 1px solid #c3c3c3;
  display: flex;
}

.box {
  width: 50px;
  height: 50px;
}

#col-rev {
  flex-direction: column-reverse;
}

#row-rev {
  flex-direction: row-reverse;
}

.red {
  background-color: red;
}

.lightblue {
  background-color: lightblue;
}

.yellow {
  background-color: yellow;
}

Result

Specifications

Specification
CSS Flexible Box Layout Module Level 1
# flex-direction-property

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
flex-direction
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
prefix
prefix Implemented with the vendor prefix: -webkit-
Chrome – Full support
Chrome 29 (Release date: 2013-08-20)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
prefix
prefix Implemented with the vendor prefix: -webkit-
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 49 (Release date: 2016-09-20)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
footnote
footnote Since Firefox 28, multi-line flexbox is supported.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 7 (Release date: 2013-10-22)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari – Full support
Safari 9 (Release date: 2015-09-30)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
prefix
prefix Implemented with the vendor prefix: -webkit-
Chrome Android – Full support
Chrome Android 29 (Release date: 2013-08-21)
footnote Full support
Firefox for Android – Full support
Firefox for Android 49 (Release date: 2016-09-20)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox for Android – Full support
Firefox for Android 22 (Release date: 2013-06-25)
footnote
footnote Since Firefox for Android 28, multi-line flexbox is supported.
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari on iOS – Full support
Safari on iOS 9 (Release date: 2015-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
prefix
prefix Implemented with the vendor prefix: -webkit-
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView on iOS – Full support
WebView on iOS 9 (Release date: 2015-09-16)
footnote Full support
column
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 22 (Release date: 2013-06-25)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support
column-reverse
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Partial support
Firefox 22 – 80 (Release date: 2013-06-25)
footnote Partial support
footnote Before Firefox 81, overflow with column-reverse was unsupported. See bug 1042151.
Firefox – Full support
Firefox 81 (Release date: 2020-09-22)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 22 – 80 (Release date: 2013-06-25)
footnote Partial support
footnote Before Firefox for Android 81, overflow with column-reverse was unsupported. See bug 1042151.
Firefox for Android – Full support
Firefox for Android 81 (Release date: 2020-09-22)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support
row
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 22 (Release date: 2013-06-25)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support
row-reverse
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Partial support
Firefox 22 – 80 (Release date: 2013-06-25)
footnote Partial support
footnote Before Firefox 81, overflow with column-reverse was unsupported. See bug 1042151.
Firefox – Full support
Firefox 81 (Release date: 2020-09-22)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 22 – 80 (Release date: 2013-06-25)
footnote Partial support
footnote Before Firefox for Android 81, overflow with column-reverse was unsupported. See bug 1042151.
Firefox for Android – Full support
Firefox for Android 81 (Release date: 2020-09-22)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also