Font to Base64 encoder
Inlining a font in CSS as a data URI removes one request, at the cost of making the stylesheet larger by about a third of the font's size. This tool encodes one or several font files in your browser and gives you the plain Base64 string, a data: URI with the MIME type that matches the bytes, and a complete @font-face rule using the family, weight and style read from each font. It shows the exact size before and after encoding, so you can decide whether inlining is worth it.
Drop WOFF2, WOFF, TTF or OTF files to encode as Base64.
Encoded in this tab, exactly as supplied. Nothing is uploaded.
Files are read and processed in this browser tab. Nothing is uploaded — the page’s Content-Security-Policy blocks connections to any other origin.
The MIME type comes from the file, not its name
A data URI names its content type, and the @font-face src names a format. Both are taken from the container signature in the first four bytes: "wOF2" gives font/woff2 with format('woff2'), "wOFF" gives font/woff, "OTTO" gives font/otf with format('opentype'), and a TrueType header gives font/ttf with format('truetype'). A WOFF2 saved with a .woff name is still declared as WOFF2, and the result tells you the extension was wrong.
The bytes are encoded exactly as you supplied them. Nothing is converted, compressed or subsetted first, so the data URI decodes to your own file.
What the 33% means
Base64 writes every three bytes as four characters, so the encoded text is four thirds of the file, plus padding of at most two characters. A 20 kB WOFF2 becomes about 26.7 kB of CSS.
Gzip or Brotli on the stylesheet wins back most of that, because each Base64 character carries only six bits of information; the result never gets meaningfully smaller than the font file itself, since a WOFF2 is already compressed.
When inlining helps, and when it hurts
It suits a small, critical font: a single subsetted WOFF2 for a logo or headline, an HTML email, a self-contained widget or a single-file document that must work offline.
It hurts for full text fonts. The font can no longer be cached separately from the stylesheet, so any CSS change re-downloads it; the stylesheet blocks rendering until all of it arrives; and unicode-range stops saving anything, because the data is inside the CSS whether or not the page uses those characters. Encode the WOFF2 only, not every format, since a browser downloads every inline source in the stylesheet regardless of which one it uses.
When it does not work
- The browser ignores the inlined font.
Why: A Content-Security-Policy without data: in font-src blocks data URI fonts, even on the same page.
Fix: Add data: to the font-src directive, or serve the font as a file instead.
- A collection (.ttc) file is refused.
Why: @font-face loads one face per rule, and a collection holds several.
Fix: Extract the face you want on the TTC to TTF page, then encode that file.
- The stylesheet is now larger than the page.
Why: A full desktop font, or several formats of it, was inlined.
Fix: Subset the font to the characters you use and inline only the WOFF2.
Related
Web-font pack
Turn a font into a deployable web-font pack in your browser: WOFF2 and WOFF files, a correct @font-face rule with unicode-range, a preload snippet and a manifest, all in one ZIP.
Open: Web-font packSubsetter
Subset fonts in your browser with HarfBuzz hb-subset. Keep pasted text, whole Unicode blocks or standard web ranges. Layout closure is preserved and licence strings are kept.
Open: SubsetterCSS font fallback
Generate @font-face metric overrides from your font's real hhea, OS/2 and hmtx tables: size-adjust, ascent-override, descent-override and line-gap-override for Arial, Georgia, Times New Roman or Courier New.
Open: CSS font fallbackWOFF to WOFF2
Re-encode WOFF 1.0 web fonts as WOFF2 in your browser: unwrap the zlib tables, then compress with the reference Google WOFF2 encoder. Verified against the source, never uploaded.
Open: WOFF to WOFF2