Flexible length resolution
Definition and purpose
Flexbox distributes free space per line, subject to constraints. For the simple examples with no gaps, margins or padding, free space is the inner container width minus the relevant item sizes. Growth uses grow factors; shrinking uses shrink factors multiplied by the inner flex base sizes.
Weighted growth
<!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; width: 300px; } #a, #b { min-width: 0; background: #dbeafe; } #a { flex: 1 1 100px; } #b { flex: 3 1 100px; } </style> </head> <body> <div id="parent"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>The 100px surplus is shared 1:3.
Syntax and mental model
Two bases of 100px in a 300px row with grow factors 1 and 3 get 25px and 75px extra. For a 150px row with bases 100 and 200 and shrink factors 1 and 1, the scaled weights are 100 and 200; the deficit of 150px is distributed as 50 and 100px. In the full algorithm, choose grow or shrink using hypothetical sizes, initialize target sizes, freeze inflexible items, recalculate remaining free space, clamp to min/max, and freeze violating items according to the sign of total violation. Repeat until all items are frozen. Factor sums below one can leave space undistributed.
Scaled shrink
<!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; width: 300px; } #a, #b { min-width: 0; background: #dbeafe; } #parent { width: 150px; } #a { flex: 0 1 100px; } #b { flex: 0 1 200px; } </style> </head> <body> <div id="parent"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>The deficit is shared according to base size.
Common mistakes
Equal shrink factors do not imply equal pixel losses. Do not divide free space just once if a minimum or maximum is hit. Resetting min-width to zero here isolates the arithmetic; in real content consider overflow and readability.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Flex line collection and hypothetical size. Next lesson: Grid placement algorithm.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Flexible length resolution — knowledge check
Five questions on flexible length resolution.
What weights shrinking?
What is the result of 1:3 growth with 100px extra and bases 100px?
Why freeze a constrained item?
What is B width in the capped example?
Can a sum of grow factors below one leave free space?