CKTIS / CSS
Flexbox — flexible one-dimensional layout
Flexbox arranges items along one axis, distributes available space, and controls alignment. Learn about its container, layout axes, wrapping, and the flex shorthand.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
.container { display: flex; flex-direction: row; flex-wrap: nowrap; }
.item { flex: 1 1 0px; }Flexbox is a one-dimensional CSS layout model. display: flex creates a block-level container with flex layout inside; its in-flow element children become flex items.
flex-direction defines the main axis; the cross axis is perpendicular. row follows the inline axis, not necessarily horizontally. justify-content aligns along the main axis, while align-items aligns along the cross axis. flex-wrap: wrap allows additional lines, each laid out independently.
The flex shorthand sets the growth factor (flex-grow), the shrink factor (flex-shrink), and the base size (flex-basis). If both factors are specified, the growth factor must come before the shrink factor. A base size given as a length can come before the pair, as in flex: 10px 1 2, or after it. An automatic minimum size can restrict shrinking; min-width: 0 removes that obstacle in a horizontal layout. With the default reading flow, order changes the visual order of items without changing their reading order or the order of sequential keyboard navigation. In browsers that support reading-flow: flex-visual, setting it on the flex container makes sequential keyboard navigation follow the visual reading order in the writing mode. That order does not necessarily match the document order after applying order.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Flexbox</title>
<style>
.container {
display: flex;
flex-direction: row;
width: 300px;
gap: 10px;
direction: ltr;
writing-mode: horizontal-tb;
}
.item {
flex: 1 1 0px;
min-width: 0;
height: 40px;
background: lightblue;
}
</style>
<div class="container">
<div class="item">A</div>
<div class="item">B</div>
</div>
</html>Result
A: x = container left, width = 145 CSS px, height = 40 CSS px. B: x = container left + 155 CSS px, width = 145 CSS px, height = 40 CSS px. Gap = 10 CSS px.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.