The flex-direction
CSS property specifies how flex items are placed in the flex container defining the main axis and the direction (normal or reversed).
Note that the value 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.
Initial value | row |
---|---|
Applies to | flex containers |
Inherited | no |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
See Using CSS flexible boxes for more properties and information.
/* 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;
The following values are accepted:
row
row-reverse
row
but the main-start and main-end points are permuted.column
column-reverse
column
but the main-start and main-end are permuted.row | row-reverse | column | column-reverse
<h4>This is a Column-Reverse</h4> <div id="content"> <div id="box" style="background-color:red;">A</div> <div id="box" style="background-color:lightblue;">B</div> <div id="box" style="background-color:yellow;">C</div> </div> <h4>This is a Row-Reverse</h4> <div id="content1"> <div id="box1" style="background-color:red;">A</div> <div id="box1" style="background-color:lightblue;">B</div> <div id="box1" style="background-color:yellow;">C</div> </div>
#content { width: 200px; height: 200px; border: 1px solid #c3c3c3; display: -webkit-flex; -webkit-flex-direction: column-reverse; display: flex; flex-direction: column-reverse; } #box { width: 50px; height: 50px; } #content1 { width: 200px; height: 200px; border: 1px solid #c3c3c3; display: -webkit-flex; -webkit-flex-direction: row-reverse; display: flex; flex-direction: row-reverse; } #box1 { width: 50px; height: 50px; }
Specification | Status | Comment |
---|---|---|
CSS Flexible Box Layout Module The definition of 'flex-direction' in that specification. | Candidate Recommendation | Initial definition |
Feature | Firefox (Gecko) | Chrome | Edge | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support |
18.0 (18.0)[1] 20.0 (20.0) 28.0 (28.0)[2] | 21.0-webkit |
(Yes)-webkit (Yes) | 10 -ms | 12.10 | 7 -webkit |
Feature | Firefox Mobile (Gecko) | Android | Edge | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | ? |
(Yes)-webkit (Yes) | No support | 12.10 | No support |
[1] To activate flexbox support for Firefox 18 and 19, the user has to change the about:config
preference layout.css.flexbox.enabled
to true
.
[2] Multi-line flexbox is supported since Firefox 28.
In addition to the unprefixed support, Gecko 48.0 (Firefox 48.0 / Thunderbird 48.0 / SeaMonkey 2.45) added support for a -webkit
prefixed version of the property for web compatibility reasons behind the preference layout.css.prefixes.webkit
, defaulting to false
. Since Gecko 49.0 (Firefox 49.0 / Thunderbird 49.0 / SeaMonkey 2.46) the preference defaults to true
.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction