CSS flex-direction Property
Description
The flex-direction
property allows you to specify the direction in accordance with which the flex elements are located inside the flex container. The direction of flex elements is formed based on the position of two axes: the main axis of the flex container and its transverse axis , which is always located perpendicular to the main . The main axis in the ltr direction (the global HTML dir attribute, or the CSS direction property with ltr value) is located from left to right, and the transverse axis is from top to bottom (this is the default value), for the rtl value it is mirrored accordingly.
- Initial value
- row
- Applies to
- Flex containers
- Inherited
- No
- Computed value
- As specified
- Animatable
- No
- JavaScript syntax
- object.style.flexDirection
Interactive Demo
Syntax
flex-direction: row | row-reverse | column | column-reverse
Values
- rowThe main axis is the same as the orientation of the text, by default, from left to right. If the dir value is specified as rtl, then the direction of the axis goes from right to left.
- row-reverseIt looks like a row value, but the start and end points are swapped and the main axis is directed from right to left. If the dir value is specified as rtl , then the direction of the axis goes from left to right.
- columnThe main axis is vertical and directed from top to bottom.
- column-reverseThe main axis is vertical, but the position of the start and end points changes and the axis is directed from bottom to top.
Example
<h3>flex-direction: row;</h3>
<div class="container"><div>A</div><div>B</div><div>C</div></div>
<h3>flex-direction: column;</h3>
<div class="container2"><div>A</div><div>B</div><div>C</div></div>
<h3>flex-direction: row-reverse;</h3>
<div class="container3"><div>A</div><div>B</div><div>C</div></div>
<h3>flex-direction: column-reverse;</h3>
<div class="container4"><div>A</div><div>B</div><div>C</div></div>
.container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
}
.container2 {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
}
.container3 {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row-reverse;
flex-direction: row-reverse;
}
.container4 {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column-reverse;
flex-direction: column-reverse;
}
div>div {
width: 50px;
height: 50px;
margin: 5px;
border: 3px solid orange;
}
Browser Support
The following table will show you the current browser support for the CSS flex-direction
property.
Desktop | |||||
12 | 29 | 81 | 12.1 | 9 |
Tablets / Mobile | |||||
29 | 81 | 12.1 | 9 | 2 | 4.4 |
Last updated by CSSPortal on: 1st January 2024