Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/fonts.md
1---2name: fonts3description: Loading Google Fonts and local fonts in Remotion4metadata:5tags: fonts, google-fonts, typography, text6---78# Using fonts in Remotion910## Google Fonts with @remotion/google-fonts1112The recommended way to use Google Fonts. It's type-safe and automatically blocks rendering until the font is ready.1314### Prerequisites1516First, the @remotion/google-fonts package needs to be installed.17If it is not installed, use the following command:1819```bash20npx remotion add @remotion/google-fonts # If project uses npm21bunx remotion add @remotion/google-fonts # If project uses bun22yarn remotion add @remotion/google-fonts # If project uses yarn23pnpm exec remotion add @remotion/google-fonts # If project uses pnpm24```2526```tsx27import { loadFont } from "@remotion/google-fonts/Lobster";2829const { fontFamily } = loadFont();3031export const MyComposition = () => {32return <div style={{ fontFamily }}>Hello World</div>;33};34```3536Preferrably, specify only needed weights and subsets to reduce file size:3738```tsx39import { loadFont } from "@remotion/google-fonts/Roboto";4041const { fontFamily } = loadFont("normal", {42weights: ["400", "700"],43subsets: ["latin"],44});45```4647### Waiting for font to load4849Use `waitUntilDone()` if you need to know when the font is ready:5051```tsx52import { loadFont } from "@remotion/google-fonts/Lobster";5354const { fontFamily, waitUntilDone } = loadFont();5556await waitUntilDone();57```5859## Local fonts with @remotion/fonts6061For local font files, use the `@remotion/fonts` package.6263### Prerequisites6465First, install @remotion/fonts:6667```bash68npx remotion add @remotion/fonts # If project uses npm69bunx remotion add @remotion/fonts # If project uses bun70yarn remotion add @remotion/fonts # If project uses yarn71pnpm exec remotion add @remotion/fonts # If project uses pnpm72```7374### Loading a local font7576Place your font file in the `public/` folder and use `loadFont()`:7778```tsx79import { loadFont } from "@remotion/fonts";80import { staticFile } from "remotion";8182await loadFont({83family: "MyFont",84url: staticFile("MyFont-Regular.woff2"),85});8687export const MyComposition = () => {88return <div style={{ fontFamily: "MyFont" }}>Hello World</div>;89};90```9192### Loading multiple weights9394Load each weight separately with the same family name:9596```tsx97import { loadFont } from "@remotion/fonts";98import { staticFile } from "remotion";99100await Promise.all([101loadFont({102family: "Inter",103url: staticFile("Inter-Regular.woff2"),104weight: "400",105}),106loadFont({107family: "Inter",108url: staticFile("Inter-Bold.woff2"),109weight: "700",110}),111]);112```113114### Available options115116```tsx117loadFont({118family: "MyFont", // Required: name to use in CSS119url: staticFile("font.woff2"), // Required: font file URL120format: "woff2", // Optional: auto-detected from extension121weight: "400", // Optional: font weight122style: "normal", // Optional: normal or italic123display: "block", // Optional: font-display behavior124});125```126127## Using in components128129Call `loadFont()` at the top level of your component or in a separate file that's imported early:130131```tsx132import { loadFont } from "@remotion/google-fonts/Montserrat";133134const { fontFamily } = loadFont("normal", {135weights: ["400", "700"],136subsets: ["latin"],137});138139export const Title: React.FC<{ text: string }> = ({ text }) => {140return (141<h1142style={{143fontFamily,144fontSize: 80,145fontWeight: "bold",146}}147>148{text}149</h1>150);151};152```153