Flex line collection and hypothetical size
Definition and purpose
Flex line collection decides which items share a line before flexible lengths are distributed. The flex base size is the starting main size, calculated before clamping by the main-axis minimum and maximum. The hypothetical main size is the base size clamped by those constraints, with the content box floored at zero.
Collect three items
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #parent { display: flex; flex-wrap: wrap; width: 250px; gap: 10px; } #parent > div { flex: 0 0 70px; min-width: 0; height: 20px; background: #dbeafe; } </style> </head> <body> <div id="parent"> <div id="a">A</div> <div id="b">B</div> <div id="c">C</div> </div> </body></html>All three fit in the first line.
Syntax and mental model
For a wrapping row, the browser collects items in order-modified document order using outer hypothetical main sizes and gaps. Three 70px items and two 10px gaps occupy 230px of the 250px container. If B has min-width: 110px, the required total becomes 270px; C moves to the second line. Flexible shrinking happens after collection, not as a way to force all items onto the first line. A single oversized item still occupies a line.
Minimum changes wrapping
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #parent { display: flex; flex-wrap: wrap; width: 250px; gap: 10px; } #parent > div { flex: 0 0 70px; min-width: 0; height: 20px; background: #dbeafe; } #parent > #b { min-width: 110px; } </style> </head> <body> <div id="parent"> <div id="a">A</div> <div id="b">B</div> <div id="c">C</div> </div> </body></html>The hypothetical size of B increases; C starts a new line.
Common mistakes
Do not use flex-basis alone to predict wrapping. Main-axis minimums, margins, borders and gaps matter. In a column, the main axis is the block direction rather than horizontal width in ordinary horizontal writing.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Nested flex and baseline alignment, Grid versus flex and composition, Formatting context edge cases. Next lesson: Flexible length resolution.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Flex line collection and hypothetical size — knowledge check
Five questions on flex line collection and hypothetical size.
Which size governs line collection?
When are flexible lengths resolved?
What is the combined size of three 70px items and two 10px gaps?
What changes when B has min-width 110px?
Where does an oversized first item go?