Skip to main content
SebasVergaraP

Control engineer and full-stack WordPress developer.

Self-hosting fonts without the layout shift

1 minute read

Self-hosting removes a third-party request and a third-party cookie. It also removes the one thing a font CDN gives you for free: somebody else has already worked out how to stop the swap from moving the page.

Metric-matched fallbacks

A fallback face with overridden metrics occupies nearly the same space as the real one, so the swap changes the shape of the letters rather than the position of everything below them.

theme.css
/* Metric-matched fallback for Inter. */
@font-face {
  font-family: "Inter Fallback";
  src: local('Arial'), local('ArialMT');
  ascent-override: 90.4365%;
  descent-override: 22.518%;
  line-gap-override: 0%;
  size-adjust: 107.1194%;
}

What was measured

CaseFilesTransferredCLS
Cold cache, English article269 KiB0
Cold cache, article with code3109 KiB0
Spanish article269 KiB0

No preload is declared. Preloading a font competes with the largest contentful paint fetch, and with a metric-matched fallback the swap is invisible enough that it is not worth the contention.

About the author

Sebastian Vergara is a Control Engineer and Full-Stack & WordPress Developer with over 7 years of experience in full-stack web development. His expertise encompasses end-to-end website design and launch, custom web and mobile application development, server administration, web security, search engine optimization (SEO), and database control.

Leave a comment

Your email address will not be published. Required fields are marked.