Course contentsShow
← Web Development
Lesson 1294 of 2,98223. Web Font OptimizationFree lesson

The <link rel="preload"> Syntax for Fonts

Proper syntax including as="font", type, crossorigin, and href attributes.

The <link rel="preload"> Syntax for Fonts

What you'll learn: How to correctly write the preload link tag to fetch fonts early and avoid layout shifts.

What Is Font Preloading?

When you tell the browser to preload a font, you're giving it a heads-up: "You'll need this file soon, so start downloading it now!" This happens before the browser would normally discover it buried inside your CSS. Think of it like calling ahead to a restaurant so your table is ready when you arrive.

The Complete Syntax

Here's the proper structure for preloading a web font:

<link rel="preload" 
      href="/fonts/myfont.woff2" 
      as="font" 
      type="font/woff2" 
      crossorigin>

Let's break down each required attribute:

rel="preload"

Tells the browser this is a preload instruction, not a regular stylesheet or resource.

as="font"

Specifies the resource type. This helps the browser prioritize the download correctly and apply the right security policies.

type="font/woff2"

Indicates the font format (woff2, woff, ttf, etc.). This lets the browser skip downloading formats it doesn't support.

crossorigin

Critical: Even if your font is on the same domain, you must include this attribute. Fonts are fetched using anonymous CORS mode, and omitting crossorigin will cause the font to be downloaded twice—once by the preload and again when CSS requests it.

href="/fonts/myfont.woff2"

The actual path to your font file.

Why Each Attribute Matters

Missing as="font" or crossorigin are common mistakes that break preloading entirely. The browser won't recognize the preloaded font when CSS asks for it, defeating the entire purpose.

Key Takeaway: Use <link rel="preload" href="..." as="font" type="font/woff2" crossorigin> with all five parts to ensure fonts load early without duplicate downloads.