CSS flex-direction Property

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

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

Item 1
Item 2
Item 3

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
Edge Chrome Firefox Opera Safari
12298112.19
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
298112.1924.4

Last updated by CSSPortal on: 1st January 2024