Skip to main content

loadFont()v4.0.165

Part of the @remotion/fonts package.

Load a local or remote font for use in Remotion.
Automatically blocks the render until the font is ready.
If the font fails to load (for example, the URL returns a 404), the render fails with an error.

Usage​

MyComp.tsx
import { loadFont } from "@remotion/fonts"; import { AbsoluteFill, staticFile } from "remotion"; loadFont({ family: "Bangers", url: staticFile("bangers.ttf"), }).then(() => console.log("Font loaded!")); export const GoogleFontsExample: React.FC = () => { return ( <AbsoluteFill style={{ fontFamily: "Bangers", }} > <h1>Local Font</h1> </AbsoluteFill> ); };

Loading a font URL from input props​

If the font URL comes from an input prop, call loadFont() in a useEffect() inside the component instead of at the top level of the file.
Create a delayRender() handle when the component mounts, so that the render waits until the effect has loaded the font:

MyComp.tsx
import { loadFont } from "@remotion/fonts"; import { useEffect, useState } from "react"; import { AbsoluteFill, useDelayRender } from "remotion"; export const MyComp: React.FC<{ fontUrl: string; }> = ({ fontUrl }) => { const { delayRender, continueRender, cancelRender } = useDelayRender(); const [handle] = useState(() => delayRender(`Loading font ${fontUrl}`)); useEffect(() => { loadFont({ family: "CustomFont", url: fontUrl }) .then(() => continueRender(handle)) .catch((err) => cancelRender(err)); }, [fontUrl, handle, continueRender, cancelRender]); return ( <AbsoluteFill style={{ fontFamily: "CustomFont" }}> <h1>Dynamic font</h1> </AbsoluteFill> ); };

Options​

family​

Give the family a name.
You can then reference that name in your CSS using fontFamily.

url​

Where to load the font from. Can be a local file using staticFile() or a URL.

format?​

Defines the format of the font file. By default, Remotion derives it from the file extension of the URL. From v4.0.544, it ignores query strings and hashes.
Override with one of the following values explicitly: woff2, woff, opentype, truetype.

Pass this option if the URL has no file extension, for example a font served by an API endpoint.

ascentOverride?​

Defines the ascent metric for the font.

descentOverride?​

Defines the descent metric for the font.

display?​

Equivalent to the CSS font-display property.
Determines how a font face is displayed based on whether and when it is downloaded and ready to use.

featureSettings?​

Equivalent to the CSS font-feature-settings property. Allows control over advanced typographic features in OpenType fonts.

lineGapOverride?​

Defines the line gap metric for the font.

stretch?​

Equivalent to the CSS font-stretch property. Specify what kind of stretch the loaded font has.

style?​

Equivalent to the CSS font-style property. Specify what kind of style the loaded font has.

weight?​

Equivalent to the CSS font-weight property. Specify what kind of weight the loaded font has.

unicodeRange?​

The range of Unicode code points to be used from the font.

Compatibility​

BrowsersEnvironments
Chrome
Firefox
Safari

See also​