A layout can need room to grow without becoming uncomfortably wide. The CSS `max-width` property sets an upper limit on an element’s width. It can cap a growing flex item, keep a liquid page readable on large screens, or limit the length of text lines. section 5.3 section 6.3.4 section 8.1.5
Cap flex growth
Suppose three items in a 600px flex container have `flex-grow` values of 1, 2, and 3. Their proposed widths are 150px, 200px, and 250px. Setting `max-width: 220px` on each item caps the third at 220px, leaving 30px unused. The browser distributes that space between the unconstrained items in a 1:2 ratio. The rendered widths become 160px, 220px, and 220px—exactly 600px in total. The cap is a hard stop for an item, not a reason to leave available space unused. section 5.3.2
Listing 5.9 Using max-width to limit growing
.container {
display: flex;
width: 600px;
}
.item {
max-width: 220px; #1
}
.item-1 {
flex-grow: 1;
flex-basis: 100px;
}
.item-2 {
flex-grow: 2;
flex-basis: 100px;
}
.item-3 {
flex-grow: 3;
flex-basis: 100px;
}
The CSS listing pairs a 220px cap with three different `flex-grow` values, making the redistribution example easy to check. section 5.3.2
For a liquid layout, first choose the widest outer container that still supports comfortable reading and navigation—for example, `body { max-width: 960px; }`. Then convert fixed child widths to percentages of their parent: a 640px article in a 960px parent becomes `(640 / 960) × 100 = 66.67%`; a 320px aside becomes 33.33%. The children can scale with the available width while the outer container has a ceiling. section 6.3.4
Text width can also be chosen alongside font size and line height. A full-width article can produce lines that are difficult to scan; one worked adjustment pairs a 20px font size and 1.41 line height with a 600px maximum width. For a horizontal flex axis, `max-width` limits growth; for a vertical main axis, the corresponding constraint is `max-height`. section 8.1.5 section 5.3
The constraint matters in CSS Grid too. An `auto` column respects an element’s `max-width` when determining how wide it may grow. A sidebar can therefore use an `auto` track with `min-width` and `max-width` to stay within chosen bounds as the viewport changes. section 4.4.2




