CSS flex-direction Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The flex-direction property sets how flex items are placed in a flex container. It defines the main axis and whether items run in the normal or reversed direction along that axis.

Use it on an element with display: flex or inline-flex. The initial value is row. It is not inherited. Pair it with flex-wrap using the flex-flow shorthand when you need both.

Baseline · Widely available.

Not deprecated and not experimental. Available across browsers since about September 2015.

Accessibility.

row-reverse and column-reverse change visual order only. DOM / tab / screen-reader order stay the same. Prefer changing HTML order when reading order matters.

CSS Syntax

syntax.css
flex-direction: row | row-reverse | column | column-reverse | initial | inherit;

In left-to-right pages, row runs left to right and column runs top to bottom.

Property Values

ValueDescriptionTry it
rowDefault. Main axis follows the text direction (left → right in LTR)Try it
row-reverseSame axis as row, but items start from the opposite endTry it
columnMain axis follows the block axis (top → bottom)Try it
column-reverseSame axis as column, but items start from the bottomTry it
initialSets this property to its default value, rowTry it
inheritInherits this property from the parent elementTry it

How to Use flex-direction

Set the container to flex, then choose the main-axis direction.

  1. On the parent, set display: flex (or inline-flex).
  2. Set flex-direction to row, column, or a reverse value.
  3. Use justify-content along the main axis and align-items on the cross axis.
  4. Add flex-wrap (or flex-flow) when items should wrap onto new lines.
GoalTypical value
Horizontal toolbar / navrow
Stacked mobile menu / formcolumn
Visual flip onlyrow-reverse / column-reverse (check a11y)

Live Preview

Three labeled items. Change flex-direction and watch the main axis move.

DOM order stays 1 → 2 → 3. Reverse values only change what you see.

Flex container
1
2
3

flex-direction: row

CSS Examples

Each snippet shows only display: flex and flex-direction. Use Try It Yourself for a live editor.

Example 1 — Row (Default)

Place items side by side along the horizontal main axis.

CSS
<style>
  section {
    display: flex;
    flex-direction: row;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</section>
Try It Yourself

How It Works

  1. Create a flex container. display: flex makes the children flex items.
  2. Choose the main axis. flex-direction: row uses the inline axis.
  3. Place items in order. Item 1 starts at the inline-start edge; 2 and 3 follow.
  4. Default tip. You can omit row because it is the initial value.

Example 2 — Column

Stack items vertically along the block axis.

CSS
<style>
  section {
    display: flex;
    flex-direction: column;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</section>
Try It Yourself

How It Works

  1. Switch the main axis. column makes the block axis the main axis.
  2. Stack from the top. Items flow top to bottom in normal writing modes.
  3. Main-size properties change meaning. flex-basis now starts as height, not width.
  4. Common use. Mobile menus, forms, and card stacks often use column.

Example 3 — Row Reverse

Flip the visual order on the same horizontal axis.

CSS
<style>
  section {
    display: flex;
    flex-direction: row-reverse;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</section>
Try It Yourself

How It Works

  1. Keep the horizontal axis. Items still sit in a row.
  2. Start from the other end. Item 1 is placed at the inline-end edge.
  3. Visual order flips. You see 3, then 2, then 1 — but the HTML order is unchanged.
  4. Accessibility check. If reading order matters, reorder the markup instead of using reverse.

Edge Cases & Pitfalls

Most surprises come from main-axis meaning or reverse order.

container

Only works on flex containers

Set display: flex or inline-flex first. On a normal block, flex-direction does nothing.

a11y

Reverse breaks visual vs DOM order

Keyboard focus and screen readers still follow the HTML. Do not use reverse just to “fix” reading order.

axes

Main and cross axes swap roles

In column, justify-content moves items vertically and align-items moves them horizontally.

writing mode

row follows writing direction

With direction: rtl or dir="rtl", row runs right to left and row-reverse flips that again.

shorthand

Use flex-flow with wrap

flex-flow: column wrap sets direction and wrap together. A later shorthand can overwrite both.

Browser Support

flex-direction is a browser CSS property for flex containers. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

flex-direction

Supported in all modern browsers since about September 2015. Part of the CSS Flexible Box Layout module.

98% Flex support
Google Chrome 29+
Full support
Mozilla Firefox 20+
Full support
Apple Safari 9+
Full support
Microsoft Edge 12+
Full support
Opera 17+
Full support
Samsung Internet 2+
Full support
Internet Explorer 11
Partial support
flex-direction Widely supported

Bottom line: Safe for production flex layouts. Watch accessibility when using reverse values. It is not a runtime API.

Key Takeaways

  • Role: choose the flex container’s main axis and direction.
  • Default: row — items follow the text direction.
  • Column: stacks items; grow, shrink, and basis apply vertically.
  • Reverse: visual flip only — keep DOM order sensible for accessibility.

One line: flex-direction picks the main axis — row sideways, column stacked, reverse only flips the view.

Frequently Asked Questions

It sets the main axis of a flex container and whether items run in the normal or reversed direction along that axis.
The initial value is row, which places items along the inline axis (left to right in left-to-right languages).
row lays items out horizontally along the text direction. column stacks them vertically along the block axis.
They flip the main-axis direction. Visual order changes, but DOM order stays the same — which can confuse keyboard and screen-reader users.
It changes which axis is the main axis. In a row, flex-basis is the starting width; in a column, it is the starting height.
It is Baseline and widely available in modern browsers since about September 2015. It is a browser CSS property for flex containers, not a Node.js feature.

Next: flex-flow

Learn the shorthand that sets flex-direction and flex-wrap together.

flex-flow tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful