Web/CSS/flex-direction

From Get docs


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


The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

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

/* 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: 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 permuted.
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 permuted.

Accessibility concerns

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 value row
Applies to flex containers
Inherited no
Computed value as specified
Animation type discrete

Formal syntax

row | row-reverse | column | column-reverse

Examples

Reversing flex container columns and rows

HTML

<h4>This is a Column-Reverse</h4>
<div id="content">
  <div class="box" style="background-color:red;">A</div>
  <div class="box" style="background-color:lightblue;">B</div>
  <div class="box" style="background-color:yellow;">C</div>
</div>
<h4>This is a Row-Reverse</h4>
<div id="content1">
  <div class="box1" style="background-color:red;">A</div>
  <div class="box1" style="background-color:lightblue;">B</div>
  <div class="box1" style="background-color:yellow;">C</div>
</div>

CSS

#content {
  width: 200px;
  height: 200px;
  border: 1px solid #c3c3c3;
  display: flex;
  flex-direction: column-reverse;
}

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

#content1 {
  width: 200px;
  height: 200px;
  border: 1px solid #c3c3c3;
  display: flex;
  flex-direction: row-reverse;
}

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

Result

Specifications

Specification Status Comment
CSS Flexible Box Layout ModuleThe definition of 'flex-direction' in that specification. Candidate Recommendation Initial definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
flex-direction

Chrome Full support 29


Full support 29


Full support 21

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Edge Full support 12


Full support 12


Full support 12

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Firefox Partial support 20

Notes'

Partial support 20

Notes'

Notes' Since Firefox 28, multi-line flexbox is supported. Notes' Does not support overflow when using *-reverse. See bug 1042151 for more info. No support 18 — 20

Disabled'

Disabled' From version 18 until version 20 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config. Full support 49

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit- Full support 44

Prefixed' Disabled'

Prefixed' Implemented with the vendor prefix: -webkit- Disabled' From version 44: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.

IE Full support 11


Full support 11


Full support 10

Prefixed'

Prefixed' Implemented with the vendor prefix: -ms-

Opera Full support 12.1


Full support 12.1


Full support 15

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Safari Full support 9


Full support 9


Full support 7

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

WebView Android Full support 4.4


Full support 4.4


Full support ≤37

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Chrome Android Full support 29


Full support 29


Full support 25

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Firefox Android Partial support 20

Notes'

Partial support 20

Notes'

Notes' Since Firefox 28, multi-line flexbox is supported. Notes' Does not support overflow when using *-reverse. See bug 1042151 for more info. No support 18 — 20

Disabled'

Disabled' From version 18 until version 20 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config. Full support 49

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit- Full support 44

Prefixed' Disabled'

Prefixed' Implemented with the vendor prefix: -webkit- Disabled' From version 44: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.

Opera Android Full support 12.1


Full support 12.1


Full support 14

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Safari iOS Full support 9


Full support 9


Full support 7

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Samsung Internet Android Full support 2.0


Full support 2.0


Full support 1.5

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

Legend

Full support  
Full support
Partial support  
Partial support
See implementation notes.'
See implementation notes.
User must explicitly enable this feature.'
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.'
Requires a vendor prefix or different name for use.


See also