Educational guide to text-fit
Fit text to the available space
Compare growth, shrinking, and per-line fitting. Start with a readable size, limit scaling, and preserve wrapping text when the experimental enhancement is unavailable.
Mental model
text-fit scales text during layout to fill the available inline space. It applies to block containers and is inherited. It differs from justify, which distributes spacing, and from selecting a font width with font-stretch.
- Available space
The block needs a width determined by layout. text-fit does not change its intrinsic size: a fit-content width does not itself create room to grow.
- Starting size
font-size sets the base. none does not scale; grow only enlarges and shrink only reduces. Choose one direction, not both at once.
- Factor and limit
The mode determines which lines share a factor. A percentage limits how much they can grow or shrink relative to the starting size.
Grow with an explicit limit
Declare direction, mode, and percentage, in that order. grow consistent 180% permits at most 1.8 times the base size; 120% permits 1.2 times. Reaching the limit may leave space unfilled, which is a valid result.
One phrase without fitting and with two maximums
text-fit: none
Design with CSS
text-fit: grow consistent 120%
Design with CSS
text-fit: grow consistent 180%
Design with CSS
The percentage is a scaling factor, not a percentage of the container. With grow it must be at least 100%; with shrink, between 0% and 100%. Omitting it or using a percentage outside that range leaves scaling unlimited. The playground restricts its controls; those ranges do not cover all CSS syntax.
One shared factor or a factor per line
consistent, the default mode, uses a shared factor for every line. per-line calculates each line separately, except the last one and lines ending in a forced break. per-line-all includes those lines too.
Natural wrapping, a br, and a short final line
grow consistent 180%
Text layout depends on the available width and on the words that fit on each line.
With CSS
grow per-line 180%
Text layout depends on the available width and on the words that fit on each line.
With CSS
grow per-line-all 180%
Text layout depends on the available width and on the words that fit on each line.
With CSS
per-line-all can overemphasize a short final word. Use it for short headings where that hierarchy is intentional; a uniform size is usually more predictable for continuous reading. text-wrap chooses line breaks and text-fit chooses scaling; they are not interchangeable.
Shrink without making nowrap mandatory
With white-space: normal, words usually wrap before shrinking is needed. nowrap makes shrink observable on a single line, but the minimum scale may still prevent text from fitting. It does not guarantee freedom from overflow.
An enhancement conditional on available space
Base · 2rem with wrapping allowed
Design interfaces with readable words
Enhancement · shrink consistent 80% from 32rem
Design interfaces with readable words
Fitting does not change the computed font-size: it may still report 2rem even when the glyphs look smaller. Other properties’ em lengths are not recalculated using the scale either. Check the actual rendering and let the block grow; do not fix its height or clip content to hide a reached limit.
Common mistakes
Fitting makes no visible difference
- Expected result
- Scaling responds to the space left on the line.
- Cause
- The block sizes itself to its content, words already wrap, or per-line excludes every line ending in a forced break.
- Solution
- Check the used width, direction, and breaks. Compare none with a moderate limit; use per-line-all only if you want to include the last line and forced breaks too.
Text still overflows or becomes tiny
- Expected result
- The full content stays readable and accessible.
- Cause
- nowrap prevents wrapping and the minimum is not enough to fit, or shrinking has no useful minimum.
- Solution
- Restore white-space: normal, provide more space, or change the layout. Test long content and translations; unlimited shrinking does not solve layout constraints.
Zoom does not enlarge text as expected
- Expected result
- Users can enlarge text without losing information or functionality.
- Cause
- Fitting text back into the same apparent width can counteract enlargement. The CSS draft keeps this issue open.
- Solution
- Check actual zoom and text preferences. Keep a rem base, allow reflow, and use fitting selectively; if it prevents enlargement, disable it in that design. A percentage alone does not guarantee accessibility.
Support and compatibility
text-fit remains experimental with limited availability, defined in the CSS Text Level 5 draft. BCD records Chrome 150 and Edge 150 for the property, all three modes, and percentages; Firefox and Safari have no support at the consultation date below.
The examples use @supports for the syntax they apply. This checks acceptance, not fitting quality, zoom behavior, or universal compatibility. Without support, font-size and wrapping remain: a readable fallback, not a reproduction of scaling. No polyfill or JavaScript simulation is added.