The flex-direction property controls which way flex items flow inside a container — horizontally in a row or vertically in a column, including reversed directions.
01
Main axis
Row or column.
02
Default row
Left to right.
03
column
Stack vertically.
04
Reverse values
Flip the flow.
05
Container only
On flex parent.
06
Responsive
Switch on mobile.
Fundamentals
Introduction
The flex-direction property in CSS is a crucial part of the Flexible Box Layout Module, commonly known as Flexbox. This property specifies the direction in which the flex container’s children (the flex items) are placed. It allows developers to control the flow of items in a container, making it easier to design responsive and flexible layouts.
Definition and Usage
Apply flex-direction on a flex container (an element with display: flex or display: inline-flex). Use row for horizontal toolbars and nav bars, column for stacked cards or mobile menus, and reverse values when you need the visual order flipped without changing HTML source order.
💡
Beginner Tip
flex-direction defines the main axis. Properties like justify-content align items along this axis, while align-items works on the cross axis.
Foundation
📝 Syntax
The syntax for the flex-direction property is as follows:
syntax.css
container{flex-direction:direction;}
Here, direction can be one of the following values:
The default value of the flex-direction property is row, which means the flex items are laid out in a horizontal direction, from left to right.
Syntax Rules
Apply on the flex container, not on individual flex items.
Requires display: flex or display: inline-flex on the same element.
Changing direction swaps the main and cross axes for alignment properties.
Reverse values flip visual order but keep the DOM source order for accessibility.
The property is not inherited by child elements.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
row
Applies to
Flex containers
Inherited
No
Animatable
No
Common mobile pattern
flex-direction: column on small screens
Reference
💎 Property Values
Value
Description
row
Lays out the flex items horizontally, from left to right.
row-reverse
Lays out the flex items horizontally, from right to left.
column
Lays out the flex items vertically, from top to bottom.
column-reverse
Lays out the flex items vertically, from bottom to top.
Context
Main Axis vs Cross Axis
flex-direction
Main axis
Cross axis
row / row-reverse
Horizontal
Vertical
column / column-reverse
Vertical
Horizontal
Preview
👀 Live Preview
The same three items with each flex-direction value:
row
123
column
123
row-reverse
123
column-reverse
123
Hands-On
Examples Gallery
In this example, we’ll use the flex-direction property to arrange items in a row — plus column stacking, reversed row order, and a responsive layout that switches direction on mobile.
↔ Row & Column Directions
Start with the reference example — a horizontal row of flex items.
Example 1 — Flex Direction: Row
Arrange three items horizontally in the default left-to-right direction.
A media query changes only the direction. The same HTML works for both horizontal and stacked layouts.
A11y
♿ Accessibility
Reverse values change visual order, not tab order — keyboard focus still follows DOM order.
Prefer logical source order — do not rely on row-reverse alone to fix confusing navigation sequences.
Use semantic HTML — wrap nav links in <nav> regardless of direction.
Test with keyboard and screen readers when using reverse directions on interactive lists.
Consider RTL languages — writing mode and direction affect how row vs row-reverse appear.
🧠 How flex-direction Works
1
Container becomes flex
display: flex activates Flexbox on the parent element.
Setup
2
flex-direction sets the main axis
Row = horizontal flow. Column = vertical flow. Reverse flips the start and end.
Direction
3
Items flow along the main axis
Flex items are placed in source order (or reversed) along that axis.
Layout
=
↔
Controlled item flow
Switch between horizontal and vertical layouts with one property.
Compatibility
🖥 Browser Compatibility
The flex-direction property is well-supported in all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is safe to use for production websites, but it’s always a good practice to test your layouts across different browsers to ensure compatibility.
✓ Baseline · Universal support
flex-direction everywhere
All four direction values work in every modern browser. Flexbox is a core layout feature on the web today.
99%Universal support
Google Chrome29+ · Desktop & Mobile
Full support
Mozilla Firefox28+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera17+ · Modern versions
Full support
flex-direction property99% supported
Bottom line: All four flex-direction values are safe for production. Test responsive direction changes on real mobile devices.
Wrap Up
🎉 Conclusion
The flex-direction property is a fundamental aspect of Flexbox, offering a simple way to control the layout direction of items within a flex container.
By understanding and utilizing this property, you can create responsive and flexible designs that adapt to various screen sizes and orientations. Experiment with different values to see how they affect the layout of your flex items and enhance your web design projects.
Use column for stacked mobile menus and card lists
Switch to column in media queries for responsive layouts
Pair with gap for consistent spacing between items
Remember that direction defines the main axis for justify-content
❌ Don’t
Apply flex-direction on flex items instead of the container
Use row-reverse on forms or keyboard-heavy UI without testing focus order
Forget display: flex on the parent
Assume column makes items full width automatically — set widths if needed
Rely on reverse values when reordering HTML is clearer for accessibility
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about flex-direction
Use these points when building Flexbox layouts.
5
Core concepts
↔01
Main axis
Row or column.
Purpose
→02
Default row
Horizontal flow.
Default
↓03
column
Vertical stack.
Common
🔄04
Reverse
Flip visual order.
Advanced
📱05
Responsive
Switch at breakpoints.
Pattern
❓ Frequently Asked Questions
The flex-direction property sets the main axis of a flex container. It controls whether flex items are laid out horizontally (row) or vertically (column), and whether the direction is normal or reversed.
The initial value is row, which lays out flex items horizontally from left to right in left-to-right languages.
row places items side by side along a horizontal main axis. column stacks items vertically along a vertical main axis.
They flip the main axis direction. row-reverse goes right to left; column-reverse goes bottom to top, while still following the flex container's writing mode.
Yes. flex-direction defines the main axis, so flex-grow, flex-shrink, and flex-basis apply along that axis. In a column container, flex-basis sets height instead of width.