Flexbox sizing, minimum widths and free-space distribution
Analyze sizing, wrapping and free-space distribution along the main axis of a horizontal Flexbox layout
Calculates main-axis widths in CSS px for normal-flow elements in the row direction. Supply measured content-box widths for intrinsic sizes; text and image widths are not estimated.
Displayed widths are rounded to 6 decimal places. Results may differ from a browser’s pixel distribution and rendering rounding.
Results
—
- Item count
- —
- Free space per line after flex sizing (negative means overflow)
- —px
Results update automatically when the required values are entered.
Method, applicability and sources
Calculation method
Line collection uses each item’s outer hypothetical main size (basis clamped by min/max, plus horizontal padding, borders and margins) and the gap. For each line, the hypothetical total and inner width select grow or shrink. Grow distributes free space in proportion to grow factors; shrink uses shrink × content flex-basis. Items are frozen according to the sign of min/max violations, then remaining space is redistributed. Positive free space after sizing is assigned to auto margins first, with the remainder distributed by justify-content.
Worked example (hypothetical values)
Example: inner width 300px, gap 0, two items with basis 100px, grow factors 1 and 2 and min 0px produce final content widths of 133.333…px and 166.666…px. With inner width 150px, grow 0 and shrink 1 for both items, the widths are 75px and 75px.
Applicability and limitations
Horizontal row layouts with widths specified in px, non-replaced flex items in normal flow, and any required intrinsic widths measured separately. Does not cover column, RTL, reverse or reordered layouts; percentages, em, calc(), aspect-ratio, replaced elements, complex content layout, the cross axis, absolutely positioned elements, scrollbar widths or browser-specific subpixel distribution. Border-box width and basis values must be at least the total horizontal padding and borders.
Method and sources
Method: W3C CSS Flexbox Level 1 CRD 2025-10-14, horizontal px subset v1. Data recorded: 2026-11-14.