JavaScript Document fonts Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

Document.fonts is an instance property that returns the document’s FontFaceSet—the heart of the CSS Font Loading API. Learn fonts.ready, status, checking and loading faces, adding a FontFace, and five examples with try-it labs.

01

Kind

Instance property

02

Returns

FontFaceSet

03

API

CSS Font Loading

04

Key promise

fonts.ready

05

Status

loading | loaded

06

Baseline

Widely available

Introduction

Web fonts declared with @font-face download in the background. Layout can shift when a custom face finally arrives. The CSS Font Loading API lets JavaScript wait for fonts, check whether a face is ready, and load fonts programmatically.

MDN: document.fonts returns the FontFaceSet of the document—useful for loading new fonts and checking the status of previously loaded fonts.

💡
Think of it as a font manager

FontFaceSet is a Set-like collection of FontFace objects. You can iterate it, read size / status, and await ready before measuring text.

Related Document tutorials: firstElementChild, documentElement, Document constructor.

Understanding Document.fonts

An instance property on Document. Its value is the document’s FontFaceSet (MDN).

  • ValueFontFaceSet for this document.
  • Part of — CSS Font Loading API (MDN).
  • Set-like — holds ordered FontFace objects; supports iteration / size.
  • ready — Promise for when used fonts finish loading + layout (MDN).
  • Workers — also available as self.fonts in workers (MDN FontFaceSet).

📝 Syntax

JavaScript
document.fonts

Value

The FontFaceSet interface of the document (MDN). Use it to load fonts and inspect loading status.

Common reads

JavaScript
document.fonts.status; // "loading" | "loaded"
document.fonts.size;   // number of FontFace entries
document.fonts.ready;  // Promise<FontFaceSet>

🔧 Useful FontFaceSet pieces

MemberWhat it does
readyPromise that resolves when used fonts finish loading/layout (MDN)
status"loading" or "loaded"
sizeNumber of faces in the set
check(font, text?)Whether faces are available (does not start a load)
load(font, text?)Promise that loads matching faces
add(fontFace)Add a manually created FontFace
delete / clearRemove manually added faces (CSS-connected stay)

⚡ Quick Reference

GoalCode / note
Get FontFaceSetdocument.fonts
Wait until readyawait document.fonts.ready
Set statusdocument.fonts.status
Count facesdocument.fonts.size
Is face available?document.fonts.check("16px Roboto")
Load facesawait document.fonts.load("16px Roboto")
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about document.fonts.

Type
FontFaceSet

Font manager

Promise
fonts.ready

Used fonts done

API
Font Loading

CSS module

Status
baseline

Standard

📋 Used fonts vs declared fonts

IdeaMeaning (MDN)
DeclaredFonts listed via CSS / FontFace API
UsedFonts actually needed for current layout
fonts.readyWaits for loading + layout of used fonts
Optional fontsfont-display: optional may never appear in the used set if late
Unload leftoverSome faces in the set may still be unloaded if unused

Examples Gallery

Examples follow MDN Document: fonts and the FontFaceSet interface. Use View Output or Try It Yourself for each case.

📚 Getting Started

Wait for fonts, then inspect the FontFaceSet.

Example 1 — MDN: Work After document.fonts.ready

Run code only after used fonts finish loading and layout.

JavaScript
document.fonts.ready.then((fontFaceSet) => {
  // Safe place for canvas text, measuring, etc.
  const fontFaces = [...fontFaceSet];
  console.log(fontFaces);
  // Some fonts may still be unloaded if unused (MDN)
  console.log(fontFaces.map((f) => f.status));
});
Try It Yourself

How It Works

MDN: the promise fulfills when loading and layout of all used fonts are done.

Example 2 — Read status and size

Quick snapshot of the document font set.

JavaScript
console.log("status:", document.fonts.status);
console.log("size:", document.fonts.size);

document.fonts.ready.then(() => {
  console.log("after ready:", document.fonts.status);
});
Try It Yourself

How It Works

status is "loading" or "loaded" for the whole set (MDN FontFaceSet).

📈 check, load & add FontFace

Query availability and load faces from JavaScript.

Example 3 — document.fonts.check()

Ask whether a font is available without starting a download.

JavaScript
const ok = document.fonts.check("16px system-ui");
console.log("system-ui available?", ok);

const custom = document.fonts.check('16px "MyFancyFont"');
console.log("MyFancyFont available?", custom);
Try It Yourself

How It Works

MDN: check reports whether a font is loaded but does not initiate a load when it isn’t.

Example 4 — document.fonts.load()

Request matching faces; the Promise resolves to the loaded FontFace list.

JavaScript
document.fonts
  .load("16px system-ui")
  .then((faces) => {
    console.log("loaded count:", faces.length);
    console.log(faces.map((f) => f.family));
  })
  .catch((err) => console.error(err));
Try It Yourself

How It Works

Pass a CSS font shorthand string (and optional sample text) so the browser knows which glyphs matter.

Example 5 — Add a FontFace from JavaScript

Create a face, load it, then register it on document.fonts.

JavaScript
const face = new FontFace(
  "DemoFont",
  "url(https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK.woff2)"
);

face
  .load()
  .then((loaded) => {
    document.fonts.add(loaded);
    document.body.style.fontFamily = "DemoFont, system-ui, sans-serif";
    console.log("added:", loaded.family, loaded.status);
  })
  .catch((err) => console.error("Font failed:", err));
Try It Yourself

How It Works

CORS and network rules still apply. Prefer self-hosted fonts in production apps.

🚀 Common Use Cases

  • Canvas / SVG text — draw only after fonts.ready.
  • Prevent layout thrash — measure headings once faces are loaded.
  • Dynamic branding — load a partner font with FontFace + add.
  • Feature gatescheck() before enabling a typography-heavy UI.
  • Debugging FOUT/FOIT — inspect status and each face’s status.
  • Workers — use self.fonts where available for off-main-thread work.

🧠 How document.fonts.ready Fits In

1

CSS declares @font-face

Faces appear in the document FontFaceSet as CSS-connected fonts.

Declare
2

Browser downloads used faces

Only fonts needed for current layout count toward “used.”

Load
3

Layout settles

Text reflows with the final faces (or fallbacks for optional fonts).

Layout
4

fonts.ready fulfills

Your measuring / painting code can run with stable typography.

📝 Notes

  • MDN: Baseline Widely available (since January 2020) — no Deprecated / Experimental / Non-standard banner.
  • Part of the CSS Font Loading API (MDN).
  • ready tracks used fonts; unused faces may still be unloaded (MDN).
  • delete / clear affect manually added faces; CSS-connected fonts stay (MDN).
  • Related: firstElementChild, Document constructor.

Browser Support

Document.fonts is marked Baseline Widely available on MDN (since January 2020). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Document.fonts

FontFaceSet entry point for the CSS Font Loading API — ready, check, load, and add faces.

Widely Available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Not supported
No support
Document.fonts Baseline support

Bottom line: Await document.fonts.ready before measuring text. Use FontFace + fonts.add for dynamic loads, and keep @font-face as the default declaration path.

Conclusion

Document.fonts gives you the document’s FontFaceSet—the standard way to wait for web fonts, check availability, and load faces from JavaScript. Pair it with CSS @font-face and font-display for polished typography.

Continue with forms, firstElementChild, Document constructor, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Await document.fonts.ready before measuring text
  • Declare everyday fonts with CSS @font-face
  • Use font-display thoughtfully for UX
  • Handle FontFace.load() rejections
  • Self-host fonts when licensing allows

❌ Don’t

  • Assume every declared face is in the “used” set
  • Draw canvas text before fonts settle
  • Ignore CORS errors on remote font URLs
  • Expect clear() to remove CSS-connected fonts
  • Block the whole UI on optional fonts

Key Takeaways

Knowledge Unlocked

Five things to remember about document.fonts

FontFaceSet for the CSS Font Loading API — wait, check, load.

5
Core concepts
02

Status

baseline

Standard
03

Promise

fonts.ready

Used fonts
🔎04

Query

check / load

Methods
05

Dynamic

FontFace + add

JS load

❓ Frequently Asked Questions

The FontFaceSet interface for the document. MDN: it is useful for loading new fonts and checking the status of previously loaded fonts. This is part of the CSS Font Loading API.
No. MDN marks Document.fonts as Baseline Widely available (since January 2020). It is a standard Document property.
A Promise that fulfills when loading and layout of all used fonts are done (MDN). Put measurement or paint-sensitive work inside its then/await callback.
Not necessarily. MDN notes the set of used fonts can differ from declared fonts — for example optional fonts (font-display: optional) that did not load in time.
Create a FontFace, call face.load(), then document.fonts.add(face), or use document.fonts.load("12px MyFont") to request matching faces.
FontFaceSet is also available as self.fonts in web workers (MDN FontFaceSet). Document.fonts is the document entry point in window contexts.
Did you know?

Spreading the set with [...document.fonts] (as in MDN’s example) gives you an array of FontFace objects you can map for family, status, and unicodeRange—handy for debug overlays in design tools.

Next: forms

Learn the live HTMLCollection of every <form> in the document.

forms →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful