flex-direction
Quick Summary for flex-direction
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).
Code Usage for flex-direction
/* 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: unset; 
More Details for flex-direction

flex-direction

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

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: revert; 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 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.

Flexbox & the keyboard navigation disconnect — Tink Source Order Matters | Adrian Roselli MDN Understanding WCAG, Guideline 1.3 explanations Understanding Success Criterion 1.3.2 | W3C Understanding WCAG 2.0

Formal definition

Initial valuerow
Applies toflex containers
Inheritedno
Computed valueas specified
Animation typediscrete

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="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
.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

See also

CSS Flexbox Guide: Basic Concepts of Flexbox CSS Flexbox Guide: Ordering flex items

Last modified: Sep 27, 2021, by MDN contributors

Select your preferred language English (US)EspañolFrançais日本語한국어Português (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

<display-internal>

Some layout models such as table and ruby have a complex internal structure, with several different roles that their children and descendants can fill. This page defines those "internal" display values, which only have meaning within that particular layout mode.
<display-internal> css reference