MDN self-hosted library · e01.org

FontFaceSet: check() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const font = new FontFace("molot", 'url("/shared-assets/fonts/molot.woff2")', {
  style: "normal",
  weight: "400",
  stretch: "condensed",
});

document.fonts.add(font);
js
console.log(document.fonts.check("12px molot"));
// false: the matching font is in the set, but is not yet loaded
js
console.log(document.fonts.check("12px Courier"));
// true: the matching font is a system font
js
console.log(document.fonts.check("12px i-dont-exist"));
// true: the matching font is a nonexistent font
js
console.log(document.fonts.check("12px molot, Courier"));
// false: `molot` is in the set but not yet loaded
js
function check() {
  font.load();
  console.log(document.fonts.check("12px molot"));
  // false: font is still loading
  console.log(font.status);
  // "loading"
}

check();
js
async function check() {
  await font.load();
  console.log(document.fonts.check("12px molot"));
  // true: font has finished loading
  console.log(font.status);
  // "loaded"
}

check();