---
title: "How do I preload a font or image correctly?"
description: "link rel=preload fetches a critical file early, but only if as and crossorigin match how it is used. Learn the right markup for fonts and images, and when to skip it."
url: https://www.danny.engineering/answer/html/how-do-i-preload-a-font-or-image-correctly
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:23:00.000Z
tags: ["HTML"]
---

# How do I preload a font or image correctly?

## The short answer


Add a `link` with `rel="preload"` to the head, set `as` to the type of resource, and for fonts always add `crossorigin`, even when the font is on your own domain. If the attributes do not match how the file is used later, the browser downloads it twice.


```html
<link
  rel="preload"
  href="/fonts/inter-var.woff2"
  as="font"
  type="font/woff2"
  crossorigin
/>
```


## Why it happens


The browser finds most resources while parsing HTML, but some are discovered late. A web font is only requested once the browser has downloaded the CSS, parsed it and found an element that uses the font. A background image in CSS, or a hero image inserted by JavaScript, has the same problem. That delay shows up as a flash of fallback text or a slow Largest Contentful Paint.


`rel="preload"` tells the browser to fetch a specific file straight away, with the right priority, without running it or applying it. When the real request comes later, the browser reuses the preloaded copy. For that reuse to work, the preload has to be the same kind of request:

- **`as`** sets the request type and priority. Without it, the browser fetches with low priority and cannot match the later request.
- **`crossorigin`** sets the CORS mode. Fonts are always fetched in CORS mode, so a font preload without `crossorigin` does not match and the font is downloaded again.
- **`type`** lets browsers skip formats they do not support.

## How to fix it


### Preload a critical font


Preload only the one or two font files used above the fold, usually the main body weight. Use `woff2`.


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


The URL must match the `src` in your `@font-face` rule exactly, including any query string.


```css
@font-face {
  font-family: 'Body';
  src: url('/fonts/body.woff2') format('woff2');
  font-display: swap;
}
```


### Preload a late-discovered image


For an image set in CSS or added by JavaScript, preload it with `as="image"`. For responsive images, use `imagesrcset` and `imagesizes` so the browser picks the same file it would pick for the real image.


```html
<link
  rel="preload"
  as="image"
  href="/img/hero-800.jpg"
  imagesrcset="/img/hero-800.jpg 800w, /img/hero-1600.jpg 1600w"
  imagesizes="100vw"
/>
```


### Use fetchpriority for images already in the HTML


If the hero image is a normal `img` tag in the HTML, the browser already finds it early. Preloading it adds little. Raise its priority instead, and make sure it is not lazy-loaded.


```html
<img src="/img/hero.jpg" alt="" width="1600" height="900" fetchpriority="high" />
```


### Send it as a header


You can also send a preload in a `Link` HTTP header, which the browser sees before it parses any HTML. The same rules for `as` and `crossorigin` apply.


```bash
Link: </fonts/body.woff2>; rel=preload; as=font; type="font/woff2"; crossorigin
```


## When not to preload

- Files the browser already discovers early, such as stylesheets in the head or images in the HTML.
- Every font weight and style. Each preload competes for bandwidth with the CSS and the main image, so preloading too much slows the page down.
- Files that are not used on the current page. Chrome logs a console warning when a preloaded file is not used within a few seconds of the load event.
- Resources for the next page. Use `rel="prefetch"` for those, which fetches at low priority.
- JavaScript modules. Use `rel="modulepreload"`, which also prepares the module for execution.

## Common pitfalls

- Leaving out `crossorigin` on font preloads. The font downloads twice; check the Network panel for duplicate requests.
- Leaving out `as`, or using the wrong value. The request is not reused.
- A different URL in the preload and the CSS, such as a missing version hash. The browser treats them as two files.
- Preloading a lazy-loaded image. The two hints work against each other.

## Related reading

- [MDN: rel=preload](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload)
- [MDN: fetchpriority](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#fetchpriority)
