Upload a file
  1. base64hub
  2. File tools
  3. Font to Base64

Font to Base64

Drop a font file and copy a ready @font-face rule with the font embedded as a data URI, the matching format() hint and font-display: swap.

Free no sign-up, no limits Local nothing uploaded @font-face format() hint picked for you Updated Oct 27, 2026
Drop files here, paste, or pick them
Input –Output –Size –

Processed in your browser. This page cannot send your data anywhere – how we know

How to convert a font to Base64

  1. Drop a .woff2, .woff, .ttf or .otf file on the box, or pick it with the file picker.
  2. Output as is already set to CSS @font-face. Choose Data URI or Plain Base64 if you are building the rule yourself.
  3. Copy output and paste it into your stylesheet.

For a file named Inter-Bold.woff2 the result looks like this, with the data shortened:

@font-face {
  font-family: "Inter-Bold";
  src: url("data:font/woff2;base64,d09GMgABAAAAA...") format("woff2");
  font-display: swap;
}

The font-family name comes from the file name, with the extension removed and characters other than letters, digits, spaces, - and _ replaced by spaces. Rename it to the family name you use in your CSS, and add font-weight and font-style if you embed several styles of one family.

format() hints and MIME types

FileMIME typeformat()Base64 starts with
WOFF2font/woff2woff2d09GMg
WOFFfont/woffwoffd09GRg
TrueTypefont/ttftruetypeAAEAAA
OpenType (CFF)font/otfopentypeT1RUTw

The format() hint lets a browser skip sources it cannot use without downloading them. With a single embedded source it matters less, but a hint the browser does not recognize still makes it skip the source. The tool derives the hint from the MIME type the browser reports, and some systems report fonts with unusual types. If an OTF comes out with format("truetype"), change it to opentype.

A WOFF2 that wraps a TrueType font starts d09GMgABAAA; one that wraps CFF outlines starts d09GMk9UVE8.

Keep embedded fonts small

The Base64 is a third larger than the font file, and it sits inside render-blocking CSS. A test with a 77,160-byte icon font in WOFF2 produced 102,880 characters of Base64, all of which must download before anything on the page is drawn.

To make inlining worth it:

  • Use WOFF2. For the same font it is much smaller than TTF or OTF.
  • Subset the font. Removing the glyphs you do not need, for example all scripts except Latin, can shrink a large font by most of its size. Font subsetting tools do this from the command line.
  • Inline only one face. A heading font or an icon font used above the fold is a good candidate. Body text in four weights is better served as separate files the browser can cache.

Self-contained HTML documents and canvas or SVG exports that must carry their own font are the typical places where an embedded font is the right call.

Checking a Base64 font

If text falls back to a default font, open the browser’s developer tools and look for font loading errors, then check that the data URI starts with data:font/ and the payload starts with one of the prefixes above. A file that starts PCFET0NUWVBF is an HTML page saved with a font extension. Base64 to Font decodes a string, previews the glyphs and saves the file.

FAQ

Which font format should I embed as Base64?

WOFF2. It is compressed specifically for fonts and every current browser supports it, so the Base64 is far shorter than for the same font as TTF or OTF. Only embed TTF if a tool you target cannot read WOFF2.

What format() value goes with each font type?

woff2 for WOFF2, woff for WOFF, truetype for TTF and opentype for OTF. The tool picks the hint from the file’s MIME type and falls back to truetype when the type is unknown, so check the hint for OTF and WOFF files.

Is it legal to embed a font as Base64?

That is up to the font’s license. Open licenses such as the SIL Open Font License allow it. Some commercial web-font licenses limit self-hosting or embedding, so check the terms before you inline a paid font.

Does an embedded font slow down the page?

The browser no longer makes a separate font request, but the stylesheet becomes larger and must be downloaded completely before the page renders. The trade pays off for one small, subset font; a whole family is better left as separate files.