CSS flex-direction Property
Description
The flex-direction property determines the orientation and primary flow of flex items inside a flex container by establishing the main axis and the cross axis. It tells the container whether items should be laid out along a horizontal or vertical line and whether that line’s order runs in the forward or reverse direction; this choice is fundamental because many other layout behaviors are defined relative to the main and cross axes rather than absolute horizontal/vertical directions. Because it defines the axes, it changes how space distribution, alignment, and stretching are interpreted for each item.
This property only applies to elements that are flex containers, so its effect depends on the element being set up as a flex context via display. Once a main axis is established, properties that distribute free space or align items interpret their roles in relation to that axis: for example, the property used to distribute items along the main axis is handled by justify-content, while the property that aligns items on the cross axis is align-items. Changing the main axis with flex-direction therefore changes which physical dimension each of those properties affects.
When a container can wrap onto multiple lines, the direction set here interacts with line-wrapping rules controlled by flex-wrap, and the way multiple lines are aligned relative to each other is governed by align-content. Additionally, item-level ordering and alignment semantics are interpreted along the chosen axes: the numeric ordering mechanism provided by order reorders items along the main axis, and per-item alignment via align-self targets the cross axis set by the container’s direction. In short, changing flex-direction subtly but broadly affects layout because it redefines which axis is “main” for many related flexbox behaviors.
Definition
- 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
Browser Support
The following information will show you the current browser support for the CSS flex-direction property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
