CKTIS / CSS
flex-direction — Flexbox main-axis direction
The flex-direction property sets a Flexbox container’s main-axis direction. It selects the inline or block axis and can reverse the direction in which items are laid out without changing DOM order.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
flex-direction: row | row-reverse | column | column-reverse;Set flex-direction on a container with display: flex or display: inline-flex, not on its items. It determines the main-axis direction; the cross axis is perpendicular to it. The initial value is row. The property is not inherited.
row runs the main axis from inline start to inline end, while column runs it from block start to block end. row-reverse and column-reverse reverse the respective direction. Physical directions depend on writing-mode and direction: with horizontal-tb and ltr, row runs rightward and column downward. Thus, row does not always mean horizontal layout.
Wrapping is controlled separately by flex-wrap. justify-content operates along the main axis and align-items along the cross axis, so changing flex-direction also changes their orientation.
The -reverse values do not change DOM order or replace correct content ordering. A mismatch between presentation and reading or navigation order can harm accessibility. In the example, the items appear as C B A from the left, but remain in A, B, C order in the DOM.
Examples
<!doctype html>
<meta charset="utf-8">
<title>flex-direction</title>
<style>
.items {
display: flex;
flex-direction: row-reverse;
writing-mode: horizontal-tb;
direction: ltr;
width: 160px;
gap: 8px;
}
.items > span {
flex: 0 0 40px;
height: 40px;
background: lightblue;
text-align: center;
line-height: 40px;
}
</style>
<div class="items"><span>A</span><span>B</span><span>C</span></div>Result
C B A
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.