mouthporn.net
#web fonts – @dragoni on Tumblr
Avatar

DragonI

@dragoni

"Truth is not what you want it to be; it is what it is, and you must bend to its power or live a lie", Miyamoto Musashi
Avatar

compelling case for using px instead of em and rem. rem is so sweet

Why you should use px, not em
Using em is a very elegant way to define both your text size and your layout. It keeps every element balanced and easily sizable. I’veused it before. It’s a pain.
Fonts need precision to look sharp
Let’s say your default font-size is set to 16px. You have titles at 2remand subtitles at 1.5rem. Fabulous! Your semantic hierarchy matches your visual one. If you were to change your default text size to 15px, you’d maintain that hierarchy.
But not all font sizes are equal… Considering the text of this website:
Every font needs its own specific size
Another problem with em arises when you want to change the font family, because every font renders differently at each size:
image

...

Just use pixels
If you want sharp precise interfaces, stick to px:
  • you’ll avoid any cumbersome calculations that involve 4 decimals
  • just by looking at a CSS rule, you’ll know exactly how it will look like because there’s no dependency
  • preprocessors like Sass allow easy maintenance anyway: you can have global variables for sizes, or use mixins to define variations for your elements
  • you’ll be able to align different types of elements that each require their own font-size
Avatar
A hands-on look at how to measure web font latencies and optimize their use: transfer latencies, time of initial fetch, and interaction with the critical rendering path.

Optimizing web fonts with Font Load Events API

Finally, we come to the most exciting part of this entire story: Font Load Events API. In a nutshell, this API will allow us to manage and define how and when the fonts are loaded – we can schedule font downloads at will, we can specify how and when the font will be rendered, and more. If you're familiar with the Web Font Loader JS library, then think of this API as that and more but implemented natively in the browser:
var font = new FontFace("FontA", "url(http://mysite.com/fonts/fontA.woff)", {}); font.ready().then(function() { // font loaded.. swap in the text / define own behavior. }); font.load(); // initiate immediate fetch / don't block on render tree!

...

Web font performance checklist

Web fonts offer a lot of benefits: improved readability, accessibility (searchable, selectable, zoomable), branding, and when done well, beautiful resultsIt's not a question of if web fonts should be used, but how to optimize their use. To that end, a quick performance checklist:
  1. Audit your font usage and keep it lean.
  2. Make sure font resources are optimized - see Google Web Fonts tricks.
  3. Instrument your font resources with Resource Timing: measure → optimize.
  4. Optimize the transfer latency and time of initial fetch for each font.
  5. Optimize your critical rendering path, eliminate unnecessary JS, etc.
  6. Spend some time playing with the Font Load Events API.
You are using an unsupported browser and things might not work as intended. Please make sure you're using the latest version of Chrome, Firefox, Safari, or Edge.
mouthporn.net