Performance: Align content
Align content affects how extra space is distributed in a container with multiple lines, impacting layout calculation and paint.
Jump into concepts and practice - no test required
.container { display: flex; flex-wrap: wrap; align-content: flex-start; height: 500px; } .item { flex: 1 0 100px; }
.container { display: flex; flex-wrap: wrap; align-content: stretch; height: 500px; } .item { flex: 1 0 100px; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| align-content: stretch | medium (multiple lines) | multiple reflows | medium | [X] Bad |
| align-content: flex-start | medium (multiple lines) | single reflow | low | [OK] Good |
align-content control in a flex container?align-contentalign-items aligns individual items on a single line, not spacing between lines. Font size and background color are unrelated.align-content centers the space between multiple lines in a flex container.align-items centers items on a single line, justify-content aligns along the main axis, and text-align affects inline text alignment.display: flex; flex-wrap: wrap; align-content: space-between; height: 200px;
align-content: space-between; do visually?space-between behavioralign-content property has no visible effect:display: flex; flex-wrap: nowrap; align-content: center; height: 150px;
align-content does not work here?flex-wrap valuenowrap, so all items stay on a single line.align-content worksalign-content only affects spacing between multiple lines, so it has no effect if items do not wrap.flex-wrap is set to nowrap, so items do not wrap to multiple lines -> Option Calign-content: stretch; is required and items must wrap.flex-wrap: wrap; allows multiple lines, and setting a container height (300px) lets stretching be visible.flex-wrap: nowrap; prevents wrapping, align-items affects single line items, and justify-content controls main axis, not cross axis.