The text-rendering
CSS property provides information to the rendering engine about what to optimize for when rendering text.
The browser makes trade-offs among speed, legibility, and geometric precision.
/* Keyword values */ text-rendering: auto; text-rendering: optimizeSpeed; text-rendering: optimizeLegibility; text-rendering: geometricPrecision; /* Global values */ text-rendering: inherit; text-rendering: initial; text-rendering: unset;
The text-rendering
property is an SVG property that is not defined in any CSS standard. However, Gecko and WebKit browsers let you apply this property to HTML and XML content on Windows, Mac OS X and Linux.
One very visible effect is optimizeLegibility
, which enables ligatures (ff, fi, fl, etc.) in text smaller than 20px for some fonts (for example, Microsoft's Calibri, Candara, Constantia, and Corbel, or the DejaVu font family).
Initial value | auto |
---|---|
Applies to | text elements |
Inherited | yes |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
auto
optimizeSpeed
optimizeLegibility
geometricPrecision
The browser emphasizes geometric precision over rendering speed and legibility. Certain aspects of fonts — such as kerning — don't scale linearly. So this value can make text using those fonts look good.
In SVG, when text is scaled up or down, browsers calculate the final size of the text (which is determined by the specified font size and the applied scale) and request a font of that computed size from the platform's font system. But if you request a font size of, say, 9 with a scale of 140%, the resulting font size of 12.6 doesn't explicitly exist in the font system, so the browser rounds the font size to 12 instead. This results in stair-step scaling of text.
But the geometricPrecision
property — when fully supported by the rendering engine — lets you scale your text fluidly. For large scale factors, you might see less-than-beautiful text rendering, but the size is what you would expect—neither rounded up nor down to the nearest font size supported by Windows or Linux.
Note: WebKit precisely applies the specified value, but Gecko treats the value the same as optimizeLegibility
.
auto | optimizeSpeed | optimizeLegibility | geometricPrecision
optimizeLegibility
automatically at 20px
<p class="small">LYoWAT - ff fi fl ffl</p> <p class="big">LYoWAT - ff fi fl ffl</p>
This demonstates how optimizeLegibility
is used by browsers automatically when the font-size
is smaller than 20px
:
.small { font: 19.9px 'DejaVu Serif', Constantia; } .big { font: 20px 'DejaVu Serif', Constantia; }
<p class="speed">LYoWAT - ff fi fl ffl</p> <p class="legibility">LYoWAT - ff fi fl ffl</p>
p { font: 1.5em 'DejaVu Serif', Constantia; } .speed { text-rendering: optimizeSpeed; } .legibility { text-rendering: optimizeLegibility; }
Specification | Status | Comment |
---|---|---|
Scalable Vector Graphics (SVG) 2 The definition of 'text-rendering' in that specification. | Candidate Recommendation | No change |
Scalable Vector Graphics (SVG) 1.1 (Second Edition) The definition of 'text-rendering' in that specification. | Recommendation | Initial definition |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 42 3 | ? | 32 4 | No | 15 | 5 |
auto |
Yes5 | ? | Yes6 | No | ? | Yes7 |
geometricPrecision |
138 | ? | Yes9 | No | ? | ? |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | 31 | ? | ? | 46 | No | 36 | 4.3 |
auto |
? | ? | ? | ? | No | ? | ? |
geometricPrecision |
? | ? | ? | ? | No | ? | ? |
1. From version 3 to 4.3, there is a serious bug where text-rendering: optimizeLegibility
causes custom web fonts to not render. This was fixed in version 4.4.
2. This property is only supported on Windows and Linux.
3. Initial versions had bugs on Windows and Linux that broke font substitition, small-caps, letter-spacing or caused text to overlap.
4. The optimizeSpeed
option has no effect on Firefox 4 because the standard code for text rendering is already fast and there is not a faster code path at this time. See bug 595688 for details.
5. Chrome treats auto
as optimizeSpeed
.
6. If the font size is 20 pixels or higher, Firefox treats auto
as optimizeLegibility
. For smaller text, Firefox treats auto
as optimizeSpeed
. The 20-pixel threshold can be changed with the browser.display.auto_quality_min_font_size
preference.
7. Safari treats auto
as optimizeSpeed
. See WebKit bug 41363.
8. Supports true geometric precision without rounding up or down to the nearest supported font size in the operating system.
9. Firefox treats geometricPrecision
the same as optimizeLegibility
.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/text-rendering