NEXT.JS & REACT

Custom Fonts in Next.js OG Images: Load Them Correctly

You designed an OG card with your brand typeface, deployed it, pasted the link into a chat app, and the preview shows a generic sans-serif. Or worse, a row of empty boxes where a name with an accent should be. Nothing threw an error. That silent failure is why custom fonts in Next.js OG images cost people an afternoon, and why the card that represents your link looks unfinished.

Satori is the library that turns JSX into an SVG and then a PNG for ImageResponse in Next.js and for @vercel/og. It is not a browser, so it has no access to your site's CSS, your next/font setup, or fonts installed on the server. It draws text with exactly the font data you hand it, and nothing else.

Why does my OG image ignore the font I set?

Your OG image ignores the font because Satori never sees your page's fonts. A font-family style only selects among the fonts you registered in the fonts option of the response. If the name matches nothing, Satori falls back to whatever it has.

This explains the three common symptoms:

  • Wrong typeface: the fontFamily string does not match the name you registered, so a fallback is used.
  • Wrong weight: you styled text as bold but only registered the regular file, so the bold text is drawn with the regular outlines.
  • Boxes or missing characters: the registered font has no glyph for that character, such as an accented letter, a CJK character or an emoji.

Everything that follows is a way of making those three things line up. The Satori project documents the supported font formats in its README on the Satori GitHub repository: TTF, OTF and WOFF are supported, and WOFF2 is not.

How do you load a custom font for a Next.js OG image?

You load a custom font by reading the font file into an ArrayBuffer and passing it in the fonts array, with a name, weight and style. Use a static TTF or OTF file, because that is the format Satori reads reliably.

  1. Put the font files somewhere your route can read them, for example public/fonts/Brand-Regular.ttf and public/fonts/Brand-Bold.ttf.
  2. Read each file into an ArrayBuffer inside the route handler, once per request or cached at module level.
  3. Pass them as fonts: [{ name: 'Brand', data, weight: 400, style: 'normal' }, ...], one entry per weight.
  4. Set fontFamily: 'Brand' on the root element of your JSX so every child inherits it.
  5. Render a card containing the longest, most unusual text you expect, and look at the actual PNG.

On the Edge runtime, the usual pattern is fetch(new URL('./Brand-Bold.ttf', import.meta.url)).then(r => r.arrayBuffer()) with the file sitting next to the route. On the Node runtime you can read from disk with fs.readFile and a path built from process.cwd(). Pick one and keep it consistent, because the path that works locally is the one that most often breaks after deploy.

Which font formats and weights does Satori accept?

Satori accepts TTF, OTF and WOFF files, and each weight you use needs its own registered file. The table below summarizes what to register and what to avoid.

Font inputWorks in Satori?What to do
Static TTF or OTFYesRegister one entry per weight and style
WOFFYesFine, but TTF is the safer default
WOFF2NoConvert to TTF before registering
Google Fonts CSS linkNoDownload the actual font file instead
next/font outputNoIt styles the page, not the OG route

The weight rule deserves a sentence of its own. If your layout uses 400 and 700, register both. If you register only 400 and style something as 700, you get no error and no real bold, which is easy to miss in a quick glance and obvious in a side-by-side with your site.

Why do some characters render as boxes?

Characters render as boxes when the font you registered does not contain a glyph for them. Satori cannot borrow glyphs from your operating system the way a browser does, so a missing glyph stays missing.

This matters most for user-generated text. A blog title with a curly quote, an author name with a diacritic, or a product name in another script will be the first thing to break. Brand fonts are often trimmed to Latin Basic, which looks fine on your hard-coded demo title and fails on real data.

Check coverage before you commit to a font. Open the font in a viewer, paste the worst string your content can produce, and confirm every character exists. A font with broad Unicode coverage is a better default for dynamic cards than a beautiful one with 200 glyphs. Emoji are a separate case: they are not part of ordinary text fonts, and Satori needs an extra step to draw them, described in its README.

What breaks fonts after you deploy?

The most common deploy-time break is a font path that resolves locally but not in the serverless bundle. The file exists in your repo, but the function that renders the image cannot find it at runtime, so the request fails or falls back.

A short failure walk-through shows how this hides. You develop with next dev, where the working directory is your project root and reading public/fonts/Brand-Bold.ttf succeeds. In production the function runs from a bundled output, the relative path points nowhere, and the font load throws. If you wrapped the load in a try/catch that returns an empty buffer to be safe, the card now renders with the fallback and no log line explains why.

Two habits prevent that. First, never swallow a font load error: let the route return a 500 so a broken card is loud. Second, test the deployed URL of the image route directly, not only the local one, before you trust it. Social platforms also cache a bad card aggressively, so a wrong font that goes out once can stay in previews for a long time.

Is it worth building the font plumbing yourself?

For one template and one font, yes: it is about thirty lines, and you will understand every one of them. The cost grows with the number of templates, because each one repeats the font loading, the weight table and the fallback decisions, and each is a place to introduce the silent failures above.

This is the point where a known-good starting structure saves real time. BuyCoded's OG Image Generator Boilerplate ships DejaVu Sans in Regular and Bold under public/fonts/, and its product page describes swapping in your own font as dropping TTFs into that folder and editing lib/fonts.ts, about four lines. The font family name inside Satori stays as 'Sans', so the template code does not change. Its templates are also already written to Satori's CSS subset, and the preview page surfaces errors right away.

If you have written your own and it works, you do not need this. The honest objection is that a boilerplate is more than you need for a single card, and for a single card that is correct. It earns its place when you have several templates, several people editing them, or no wish to rediscover the weight and glyph rules.

What should you check before shipping a custom OG font?

Before shipping, check four things: the file format, the registered weights, the glyph coverage and the deployed path. Each maps to one of the failures above, and each takes a minute.

  • The file is a static TTF or OTF, not WOFF2.
  • Every weight used in the JSX has its own registered entry.
  • The longest and most accented real title renders without boxes.
  • The deployed image URL, not just localhost, shows the right font.

Once those pass, the font is no longer a variable in your card. If you would rather start from templates where this is already handled, browse the BuyCoded catalog, open the OG Image Generator Boilerplate page, and read the included file list before you buy. The product page states the license terms, and purchases come with a 14-day refund policy, so you can check it against your own font and content.

Frequently asked questions

Can I use next/font in an OG image route?

No, next/font does not carry over to an OG image. It configures fonts for your rendered pages, while Satori only draws with font data you pass to the fonts option of the image response. Download the actual TTF or OTF file and register it directly in the route that generates the image.

Why does my bold text look the same as regular in an OG image?

Bold looks identical because you registered only one weight. Satori does not synthesize bold from a regular file. Register a separate font entry with weight 700 using the bold font file, and make sure the fontWeight you style in the JSX matches a weight you actually registered.

Does Satori support WOFF2 fonts?

No, Satori does not support WOFF2. According to the Satori README, TTF, OTF and WOFF are the supported formats. If your brand font only comes as WOFF2, convert it to TTF with a font tool before reading it into an ArrayBuffer and registering it.

Why do accented letters show as empty boxes in my OG card?

Empty boxes mean the registered font has no glyph for that character. Satori cannot fall back to system fonts like a browser does. Choose a font with wider Unicode coverage, or register an additional fallback font that includes the missing characters, then retest with your longest real title.

Where should I store font files for an OG image route?

Store them in a folder such as public/fonts and load them with a path that works in production, not only in development. On the Edge runtime use fetch with new URL and import.meta.url. On Node use fs.readFile with process.cwd(). Always test the deployed image URL directly.