loadFont
Loads a font and registers it in document.fonts, so CSS and canvas can use family right
away.
source is either a URL (wrapped in url() for you) or the font file’s bytes. Outside a
browser (no FontFace), it rejects with a TypeError.
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
family | string | The family name CSS will use, e.g. `‘Inter’` |
source | string | BufferSource | The font URL, or its bytes |
descriptors | FontFaceDescriptors | `weight`, `style`, `unicodeRange`, … as in a CSS `@font-face` rule (optional) |
Returns
Section titled “Returns”Promise<FontFace> — The loaded FontFace
Examples
Section titled “Examples”Load a web font before drawing text
Section titled “Load a web font before drawing text”The font is registered in document.fonts, so CSS and canvas can use it right away.
Load embedded font bytes
Section titled “Load embedded font bytes”Pass the bytes of a font file extracted from an archive or a design file.
