# Font optimization

Feature 2 of 14, in the group "First-paint levers". Labels across 23 meta-frameworks: 4 1st-party, 0 Experimental, 19 Third-party, 0 Manual.

## What it is and why it matters

A web font is discovered late: the browser finds it only after the CSS that names it has loaded. Font optimization self-hosts the files, generates the `@font-face` rules, and can preload the file. In principle, self-hosting the font (via either route) removes a cross-origin request from the critical path.

## Gotchas

- Importing Fontsource alone does not preload anything. Without a `<link rel="preload">` the browser finds the font only after the stylesheet is parsed.

## Labels

| Framework | Label | Points |
| --- | --- | --- |
| [Next](https://framework-compare.vercel.app/frameworks/next.md) | 1st-party | 2 |
| [Nuxt](https://framework-compare.vercel.app/frameworks/nuxt.md) | 1st-party | 2 |
| [SvelteKit](https://framework-compare.vercel.app/frameworks/sveltekit.md) | Third-party | 1 |
| [SolidStart](https://framework-compare.vercel.app/frameworks/solidstart.md) | Third-party | 1 |
| [TanStack Start (React)](https://framework-compare.vercel.app/frameworks/tanstack-start-react.md) | Third-party | 1 |
| [TanStack Start (Solid)](https://framework-compare.vercel.app/frameworks/tanstack-start-solid.md) | Third-party | 1 |
| [Pracht](https://framework-compare.vercel.app/frameworks/pracht.md) | 1st-party | 2 |
| [Waku](https://framework-compare.vercel.app/frameworks/waku.md) | Third-party | 1 |
| [Ember](https://framework-compare.vercel.app/frameworks/ember.md) | Third-party | 1 |
| [Astro](https://framework-compare.vercel.app/frameworks/astro.md) | 1st-party | 2 |
| [React Router](https://framework-compare.vercel.app/frameworks/react-router.md) | Third-party | 1 |
| [Qwik City](https://framework-compare.vercel.app/frameworks/qwik-city.md) | Third-party | 1 |
| [Angular (SSR)](https://framework-compare.vercel.app/frameworks/angular.md) | Third-party | 1 |
| [Marko](https://framework-compare.vercel.app/frameworks/marko.md) | Third-party | 1 |
| [Fresh](https://framework-compare.vercel.app/frameworks/fresh.md) | Third-party | 1 |
| [Analog](https://framework-compare.vercel.app/frameworks/analog.md) | Third-party | 1 |
| [Vike](https://framework-compare.vercel.app/frameworks/vike.md) | Third-party | 1 |
| [RedwoodSDK](https://framework-compare.vercel.app/frameworks/redwoodsdk.md) | Third-party | 1 |
| [Remix 3](https://framework-compare.vercel.app/frameworks/remix.md) | Third-party | 1 |
| [Void (React)](https://framework-compare.vercel.app/frameworks/void-react.md) | Third-party | 1 |
| [Void (Vue)](https://framework-compare.vercel.app/frameworks/void-vue.md) | Third-party | 1 |
| [Void (Svelte)](https://framework-compare.vercel.app/frameworks/void-svelte.md) | Third-party | 1 |
| [Void (Solid)](https://framework-compare.vercel.app/frameworks/void-solid.md) | Third-party | 1 |

## How to enable it in each framework

### Next

Label: **1st-party** (2 of 2 points).

[`next/font/google`](https://nextjs.org/docs/app/api-reference/components/font) self-hosts, subsets, generates the `@font-face`, and preloads at build time. No config beyond using it in the layout.

```tsx
import { Geist } from 'next/font/google';

const geistSans = Geist({
  display: 'block',
  subsets: ['latin'],
  variable: '--font-geist-sans',
});
```

*From this repo's `next-books/app/layout.tsx` (the `Geist_Mono` import and instance omitted).*

### Nuxt

Label: **1st-party** (2 of 2 points).

Add the official [`@nuxt/fonts`](https://nuxt.com/modules/fonts) module. It resolves the fonts used in CSS, downloads them at build time, serves them from your own origin, injects `@font-face` rules, generates fallback metrics for lower CLS, and can subset.

```ts
export default defineNuxtConfig({
  modules: [
    '@nuxt/fonts',
  ]
})
```

*Adapted from [the module page](https://nuxt.com/modules/fonts).* This port does not use it; it imports `@fontsource-variable/geist` manually, so the capability exists in the framework even though this repo took the third-party route:

```css
@import '@fontsource-variable/geist';
```

*From this repo's `nuxt-books/app/assets/css/main.css` (`optimized` branch).*

Gotchas:

- `@nuxt/fonts` reads Tailwind v4's `--font-*` theme variables, so the family name must be written there literally (not `var(--font-geist-sans)`) for it to resolve, download and preload the font.

### SvelteKit

Label: **Third-party** (1 of 2 points).

Import `@fontsource-variable/geist` ([Fontsource](https://fontsource.org)). SvelteKit has no first-party font module and [does not preload fonts by default](https://svelte.dev/docs/kit/performance); the `handle` hook's `resolve(..., { preload })` filter can add font preloads (not used here), so the font is discovered from the inlined stylesheet.

```css
@import "@fontsource-variable/geist";
```

*From this repo's `svelte-books/src/routes/layout.css` (`optimized` branch).*

### SolidStart

Label: **Third-party** (1 of 2 points).

Use `@fontsource-variable/geist` plus an explicit `<link rel="preload" as="font">` with the hashed woff2 URL ([static assets](https://v1.solidjs.com/solid-start/v2/building-your-application/static-assets); no first-party font primitive documented — that page covers `/public` and asset imports only).

```tsx
import geistLatin from "@fontsource-variable/geist/files/geist-latin-wght-normal.woff2?url";
// ...
<link rel="preload" as="font" type="font/woff2" href={geistLatin} crossorigin="" />
```

*From this repo's `solid-books/src/Document.tsx` (`optimized` branch).*

### TanStack Start (React)

Label: **Third-party** (1 of 2 points).

Import [`@fontsource`](https://fontsource.org) in your global CSS; there is no preload, so the font is discovered from the inlined CSS. No first-party font module is documented; the [production checklist](https://tanstack.com/start/latest/docs/framework/react/guide/production-checklist) only says to check font loading.

```css
@import '@fontsource-variable/geist';
```

*From this repo's `tanstack-books/src/styles/global.css` (`optimized` branch).*

### TanStack Start (Solid)

Label: **Third-party** (1 of 2 points).

Hand-write `@font-face` rules over the Fontsource woff2 files in `src/app.css`, plus an explicit woff2 preload in `__root.tsx`. No first-party font module is documented (same [production checklist](https://tanstack.com/start/latest/docs/framework/react/guide/production-checklist)).

```css
@font-face {
  font-family: "Geist Variable";
  font-display: optional;
  font-weight: 100 900;
  src: url("@fontsource-variable/geist/files/geist-latin-wght-normal.woff2") format("woff2");
}
```

```tsx
links: [
  { rel: "preload", as: "font", type: "font/woff2", href: geistLatin, crossOrigin: "anonymous" },
],
```

*From this repo's `tanstack-solid-books/src/app.css` and `src/routes/__root.tsx` (`optimized` branch; `font-style` and `unicode-range` omitted).*

### Pracht

Label: **1st-party** (2 of 2 points).

[`defineFont()`](https://pracht.resynapse.dev/docs/fonts) from `@pracht/core` generates `@font-face` rules and preload links by default; fallback-metric overrides (`sizeAdjust`, `ascentOverride`, ...) are opt-in with hand-supplied values, and there is no build-time download or subsetting, so it is not equivalent to `next/font`.

```ts
export const interRegular = defineFont({ family: "Inter", src: "/fonts/inter-400.woff2", weight: 400 });
// head: { fonts: [interRegular, interBold] }
```

*Adapted from [the fonts docs](https://pracht.resynapse.dev/docs/fonts).* This port chose `@fontsource-variable/geist` in `src/styles/global.css` instead.

### Waku

Label: **Third-party** (1 of 2 points).

Waku's docs recommend `@fontsource/*` because there is no `next/font` equivalent ([migration guide](https://waku.gg/guides/migrating-from-nextjs)). This is the `optimized` branch; `main` still loads Geist from `fonts.googleapis.com` with `display=block`.

```css
@import '@fontsource-variable/geist';
```

*From this repo's `waku-books/src/styles.css` (`optimized` branch).*

### Ember

Label: **Third-party** (1 of 2 points).

Import the font from [Fontsource](https://fontsource.org) on `optimized`; `main` loads Geist from `fonts.googleapis.com` with `preconnect` and `display=swap`. No first-party font module is documented (the [Vite guide](https://guides.emberjs.com/release/build-tools/vite) covers build setup only).

```css
@import "@fontsource-variable/geist";
```

*From this repo's `ember-books/app/styles/app.css` (`optimized` branch).*

### Astro

Label: **1st-party** (2 of 2 points).

Fonts API: top-level `fonts` config (astro@6.0.0+) plus `<Font cssVariable preload />` from `astro:assets`, not under experimental flags. Providers include Google, Bunny, Fontsource, Fontshare, Adobe, local; fonts are downloaded, cached, served from `_astro/fonts`, with a `subsets` option (default `latin`) and optimized fallbacks. `preload` defaults to false. ([fonts](https://docs.astro.build/en/guides/fonts/), [astro-assets](https://docs.astro.build/en/reference/modules/astro-assets/))

Example of building it yourself:

Register the font in the top-level `fonts` config, then render `<Font />` in the layout head. Astro downloads and serves the files itself, and `preload` adds a preload link.

```js
// astro.config.mjs
import { defineConfig, fontProviders } from 'astro/config';

export default defineConfig({
  fonts: [{
    provider: fontProviders.fontsource(),
    name: 'Roboto',
    cssVariable: '--font-roboto',
  }],
});
```

```astro
---
// src/layouts/Layout.astro
import { Font } from 'astro:assets';
---
<html>
  <head>
    <Font cssVariable="--font-roboto" preload />
  </head>
  <body><slot /></body>
</html>
```

Source: [Astro: Using custom fonts](https://docs.astro.build/en/guides/fonts/)

### React Router

Label: **Third-party** (1 of 2 points).

No first-party font primitive documented; the styling page does not cover fonts (use Fontsource or a CDN by hand). ([styling](https://reactrouter.com/explanation/styling))

Example of building it yourself:

The port installs Fontsource's variable Geist packages and imports them at the top of the global stylesheet. The packages ship the `@font-face` rules and self-hosted font files, and Vite bundles them like any other CSS import.

```css
/* app/styles/global.css */
@import '@fontsource-variable/geist';
@import '@fontsource-variable/geist-mono';
@import 'tailwindcss';

@theme {
  /* … */
  --font-geist-sans: 'Geist Variable', 'Geist', ui-sans-serif, system-ui, sans-serif;
  --font-geist-mono: 'Geist Mono Variable', 'Geist Mono', ui-monospace, monospace;
  --font-sans: var(--font-geist-sans);
  --font-mono: var(--font-geist-mono);
}
```

Source: [Fontsource: Installing fonts](https://fontsource.org/docs/getting-started/install)

### Qwik City

Label: **Third-party** (1 of 2 points).

The cookbook recommends Fontsource, manual `@font-face`, `unicode-range`, and Fontaine for fallback metrics; no preload guidance and no first-party font module documented. ([fonts](https://qwik.dev/docs/cookbook/fonts/))

Example of building it yourself:

The Qwik cookbook points to Fontsource for self-hosted files and Fontaine for fallback metrics. Install `@fontsource-variable/open-sans` and `fontaine`, import the font in the root layout, and add the Fontaine Vite plugin.

```tsx
// src/routes/layout.tsx
import '@fontsource-variable/open-sans/wght.css'
// global.css: body { font-family: "Open Sans Variable", sans-serif; }
```

```ts
// vite.config.ts
import { FontaineTransform } from 'fontaine'
// …
plugins: [
  qwikCity(), qwikVite(),
  FontaineTransform.vite({
    fallbacks: ['Arial'],
    resolvePath: (id) => new URL(`./public${id}`, import.meta.url),
  }),
],
```

Source: [Qwik: Fonts cookbook](https://qwik.dev/docs/cookbook/fonts/), [Fontsource: Qwik guide](https://fontsource.org/docs/guides/qwik)

Gotchas:

- `qwikVite` preloads every font file in the build by default (every Fontsource subset, on every page). This port turns that off with `disableFontPreload` and preloads one file.

### Angular (SSR)

Label: **Third-party** (1 of 2 points).

`optimization.fonts.inline` (default `true`) inlines external Google Fonts and Adobe Fonts CSS into the index HTML (needs internet at build). That removes one render-blocking stylesheet request, but the font files still load from the font host; no self-hosting, subsetting, or preload is documented. Self-hosting needs a package such as Fontsource, as for React Router, Qwik City, Marko, and Fresh. Our feature test confirmed this: with `fonts.inline` on, the Google CSS was inlined and the font file was still fetched from `fonts.gstatic.com`. ([workspace-config](https://angular.dev/reference/configs/workspace-config), [Fontsource](https://fontsource.org/docs/getting-started/introduction))

Example of building it yourself:

Link a Google Fonts stylesheet in `index.html` as usual. With `optimization.fonts.inline` on, the production build downloads that CSS and inlines it into the HTML, removing one render-blocking request.

```html
<!-- src/index.html -->
<head>
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet" />
</head>
```

```json
// angular.json (production configuration; needs internet access at build time)
"optimization": {
  "fonts": { "inline": true }
}
```

Source: [Angular: Workspace configuration](https://angular.dev/reference/configs/workspace-config)

Gotchas:

- The critical CSS inliner (Beasties) inlines and preloads `@font-face` only for families written literally. Tailwind v4's `font-family: var(--font-sans)` hides the name, so put the font tokens in `@theme inline`.
- `optimization.fonts.inline` only inlines the provider CSS; the font files still load from the font host and nothing is preloaded. Built-in self-hosting is an open request: [angular/angular-cli#27038](https://github.com/angular/angular-cli/issues/27038).

### Marko

Label: **Third-party** (1 of 2 points).

No font primitive documented; self-host by hand with a community package such as Fontsource (as the `marko-books` `optimized` branch does). The Core Tags reference only shows a Google Fonts `@import` inside `<html-style>` (a raw `<style>` tag). No first-party font handling documented. ([core-tag](https://markojs.com/docs/reference/core-tag), [styling](https://markojs.com/docs/guide/styling))

Example of building it yourself:

The Books port self-hosts Geist with Fontsource. The CSS `@import` pulls the package's `@font-face` rules, and Vite copies the `.woff2` files into the build with hashed names.

```css
/* src/styles/global.css */
@import '@fontsource-variable/geist';
@import '@fontsource-variable/geist-mono';
@import 'tailwindcss';

@theme {
  --font-sans: 'Geist Variable', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'Geist Mono Variable', ui-monospace, monospace;
}
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install)

### Fresh

Label: **Third-party** (1 of 2 points).

No first-party font handling documented; fonts appear only as files in `static/` referenced by URL. The third-party route is [Fontsource](https://fontsource.org) packages, which the Fresh docs do not mention. ([static-files](https://usefresh.dev/docs/concepts/static-files))

Example of building it yourself:

The Books port self-hosts Geist with Fontsource packages mapped in `deno.json`. The CSS `@import` brings in the `@font-face` rules, and Vite bundles the font files when `client.ts` imports the stylesheet.

```jsonc
// deno.json
"imports": {
  "@fontsource-variable/geist": "npm:@fontsource-variable/geist@^5.3.0"
}
```

```css
/* assets/global.css (imported from client.ts) */
@import '@fontsource-variable/geist';
@import 'tailwindcss';

@theme {
  --font-sans: 'Geist Variable', ui-sans-serif, system-ui, sans-serif;
}
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install)

### Analog

Label: **Third-party** (1 of 2 points).

No first-party font handling documented; the style pipeline guide covers stylesheet preprocessing only. The third-party route is [Fontsource](https://fontsource.org) packages imported from the global stylesheet. ([style-pipeline](https://analogjs.org/docs/guides/style-pipeline))

Example of building it yourself:

Install a Fontsource package and import it from the global stylesheet. Vite bundles the font files with hashed names and serves them from your own origin.

```css
/* src/styles.css (npm install @fontsource-variable/open-sans) */
@import '@fontsource-variable/open-sans';

body {
  font-family: 'Open Sans Variable', sans-serif;
}
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install)

### Vike

Label: **Third-party** (1 of 2 points).

No first-party font module documented. Vike injects `<link rel="preload" as="font">` for font files a page imports, but it does not download, subset or self-host fonts; the third-party route is [Fontsource](https://fontsource.org). ([preloading](https://vike.dev/preloading))

Example of building it yourself:

Install a Fontsource package and import it from `+Layout`. The font files are then local build assets, and Vike adds a `<link rel="preload" as="font">` for them.

```tsx
// pages/+Layout.tsx
import '@fontsource-variable/inter'
import './Layout.css' // body { font-family: "Inter Variable", sans-serif; }

export function Layout({ children }: { children: React.ReactNode }) {
  return <div id="app">{children}</div>
}
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install) · [Vike: Preloading](https://vike.dev/preloading)

Gotchas:

- Vike preloads every font file the page CSS references (here, all 12 Geist subsets); vike-react doesn't expose `injectFilter`, so narrowing it means writing your own `onRenderHtml`.

### RedwoodSDK

Label: **Third-party** (1 of 2 points).

No first-party font handling documented; the docs show font files in `public/fonts` with a hand-written `@font-face`. The third-party route is [Fontsource](https://fontsource.org). ([public-assets](https://docs.rwsdk.com/guides/frontend/public-assets))

Example of building it yourself:

Install a Fontsource package and import it at the top of the stylesheet. The package ships the `@font-face` rules and self-hosted font files, and Vite bundles them like any other CSS import.

```css
/* src/app/styles.css */
@import "@fontsource-variable/inter";
@import "tailwindcss";

@theme {
  --font-sans: "Inter Variable", ui-sans-serif, system-ui, sans-serif;
}
```

Source: [Fontsource: Installing fonts](https://fontsource.org/docs/getting-started/install)

### Remix 3

Label: **Third-party** (1 of 2 points).

No first-party font module documented. The asset server rewrites `url()` references in CSS, and a font preload is a hand-written `<link rel="preload" as="font">` using `assets.getHref()`; the third-party route is [Fontsource](https://fontsource.org). ([files-and-assets](https://docs.remix.run/files-and-assets/))

Example of building it yourself:

Install Fontsource, allow the package in the asset server, and link its stylesheet. The asset server rewrites the `url()` references in the CSS. The preload is a hand-written `<link>` with a URL from `getHref()`.

```tsx
// app/assets.ts  (npm i @fontsource-variable/inter)
export const assets = createAssetServer({
  // …
  allowPackages: ["remix", "@fontsource-variable/inter"],
  files: { extensions: [".svg", ".png", ".jpg", ".woff2"] },
});

export const fontCssHref = await assets.getHref(
  "node_modules/@fontsource-variable/inter/index.css",
);
export const fontHref = await assets.getHref(
  "node_modules/@fontsource-variable/inter/files/inter-latin-wght-normal.woff2",
);

// app/actions/document.tsx, inside <head>
<link rel="preload" href={fontHref} as="font" type="font/woff2" crossOrigin="anonymous" />
<link rel="stylesheet" href={fontCssHref} />
```

Source: [Remix: Files and assets, reference styles, images, and fonts](https://docs.remix.run/files-and-assets/)

### Void (React)

Label: **Third-party** (1 of 2 points).

No first-party font handling documented; the docs mention fonts only as CSS variables for the Markdown theme. The third-party route is [Fontsource](https://fontsource.org) packages imported from a stylesheet. ([markdown](https://void.cloud/guide/pages-routing/markdown), [static-assets](https://void.cloud/guide/edge/static-assets))

Example of building it yourself:

Install a Fontsource package so the font files become local build assets, then add the preload link from the page's `head`.

```ts
// pages/index.server.ts
import '@fontsource-variable/geist' // @font-face with font-display: swap
import fontUrl from '@fontsource-variable/geist/files/geist-latin-wght-normal.woff2?url'
import { defineHead } from 'void'

export const head = defineHead(() => ({
  link: [{ rel: 'preload', href: fontUrl, as: 'font', type: 'font/woff2', crossorigin: 'anonymous' }],
}))
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install) · [Void: Head](https://void.cloud/guide/pages-routing/head)

### Void (Vue)

Label: **Third-party** (1 of 2 points).

No first-party font handling documented; the docs mention fonts only as CSS variables for the Markdown theme. The third-party route is [Fontsource](https://fontsource.org) packages imported from a stylesheet. ([markdown](https://void.cloud/guide/pages-routing/markdown), [static-assets](https://void.cloud/guide/edge/static-assets))

Example of building it yourself:

Install a Fontsource package so the font files become local build assets, then add the preload link from the page's `head`.

```ts
// pages/index.server.ts
import '@fontsource-variable/geist' // @font-face with font-display: swap
import fontUrl from '@fontsource-variable/geist/files/geist-latin-wght-normal.woff2?url'
import { defineHead } from 'void'

export const head = defineHead(() => ({
  link: [{ rel: 'preload', href: fontUrl, as: 'font', type: 'font/woff2', crossorigin: 'anonymous' }],
}))
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install) · [Void: Head](https://void.cloud/guide/pages-routing/head)

### Void (Svelte)

Label: **Third-party** (1 of 2 points).

No first-party font handling documented; the docs mention fonts only as CSS variables for the Markdown theme. The third-party route is [Fontsource](https://fontsource.org) packages imported from a stylesheet. ([markdown](https://void.cloud/guide/pages-routing/markdown), [static-assets](https://void.cloud/guide/edge/static-assets))

Example of building it yourself:

Install a Fontsource package so the font files become local build assets, then add the preload link from the page's `head`.

```ts
// pages/index.server.ts
import '@fontsource-variable/geist' // @font-face with font-display: swap
import fontUrl from '@fontsource-variable/geist/files/geist-latin-wght-normal.woff2?url'
import { defineHead } from 'void'

export const head = defineHead(() => ({
  link: [{ rel: 'preload', href: fontUrl, as: 'font', type: 'font/woff2', crossorigin: 'anonymous' }],
}))
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install) · [Void: Head](https://void.cloud/guide/pages-routing/head)

### Void (Solid)

Label: **Third-party** (1 of 2 points).

No first-party font handling documented; the docs mention fonts only as CSS variables for the Markdown theme. The third-party route is [Fontsource](https://fontsource.org) packages imported from a stylesheet. ([markdown](https://void.cloud/guide/pages-routing/markdown), [static-assets](https://void.cloud/guide/edge/static-assets))

Example of building it yourself:

Install a Fontsource package so the font files become local build assets, then add the preload link from the page's `head`.

```ts
// pages/index.server.ts
import '@fontsource-variable/geist' // @font-face with font-display: swap
import fontUrl from '@fontsource-variable/geist/files/geist-latin-wght-normal.woff2?url'
import { defineHead } from 'void'

export const head = defineHead(() => ({
  link: [{ rel: 'preload', href: fontUrl, as: 'font', type: 'font/woff2', crossorigin: 'anonymous' }],
}))
```

Source: [Fontsource: Install](https://fontsource.org/docs/getting-started/install) · [Void: Head](https://void.cloud/guide/pages-routing/head)

---

HTML version: https://framework-compare.vercel.app/features/font-optimization · All pages: https://framework-compare.vercel.app/llms.txt · Data: https://framework-compare.vercel.app/api/index.json
