How to embed a font with Base64

Base64 puts the font inside the stylesheet, so there is no second request. That is exactly what an HTML email or a single-file report needs — and exactly what an ordinary website does not.

The trade in one line

Base64 turns every three bytes into four characters, so the file grows by about a third, and the CSS cannot be cached separately from the font. In exchange, the font travels with the document.

Encode it

  1. Open the font to Base64 converter.
  2. Drop the TTF or OTF. It is compressed to WOFF2 first, because that is the smallest starting point.
  3. Copy the generated @font-face rule — the data URI is already in it.
  4. Paste it into the email template or the single-file page and test in the client that will render it.

The Gmail problem

Gmail clips messages larger than roughly 102 KB, and its web client does not render @font-face reliably anyway. A full font family in Base64 will be clipped or ignored. What works is a subsetted font — a few dozen glyphs for a headline — and a fallback stack that looks deliberate when the font does not load.

Better uses

Single-file HTML reports that must open offline, kiosk pages, an embedded widget that cannot fetch a second file, and documentation that gets emailed as one attachment. In each case the constraint is real: one file has to carry everything.

What not to do

Do not inline a font on a normal website to save a request. Modern browsers prioritise font requests, the data URI blocks the stylesheet from completing, and you lose caching for every repeat visit.

Encode a font as a data URI

Open Font to Base64

All guides