{"success":true,"name":"load-fonts-with-next-font-not-link-tags","description":"Adding a custom or Google font to a Next.js project","category":"ai-brimind","path":"ai-brimind/load-fonts-with-next-font-not-link-tags/SKILL.md","file":"SKILL.md","content":"---\nname: load-fonts-with-next-font-not-link-tags\ndescription: \"Adding a custom or Google font to a Next.js project\"\n---\n\n# Load Fonts With next/font, Not <link> Tags\n\n## When to use\nProject is Next.js, and you are about to paste a Google Fonts <link> tag or @import into CSS.\n\n## Example request\npasting the fonts.googleapis.com <link> snippet → every visitor's browser calls Google, adding delay and a privacy dependency; next/font self-hosts it at build time. — Built-in self-hosting. | text flashes in a fallback font then jumps when the webfont lands → next/font sets size-adjusted fallbacks automatically to kill the layout shift. — Font swap without the jump. | a local branded font file in /public loaded via raw @font-face → next/font/local handles preloading and fallback metrics for it too. — Local fonts go through the same door. | five weights and three styles imported 'just in case' → each variant is real kilobytes; load the weights actually used. — Subset what you ship.\n\n## Instructions\nAct like a developer who treats fonts as part of the build, not a copy-pasted snippet. When a Next.js project needs a font: 1) Use the built-in mechanism: next/font/google for Google fonts and next/font/local for font files — declared once (typically in the root layout) and applied via the generated className or a CSS variable. This self-hosts the files at build time: no request to Google from visitors, automatic preloading, and size-adjusted fallbacks that prevent the text-jump when the font loads. 2) Never mix mechanisms: no <link> to font CDNs, no @import in global CSS alongside next/font — one loading path, or you pay twice. 3) Be deliberate about what you load: list the weights and subsets the design actually uses (e.g. 400 and 700, latin) and request only those; 'variable' fonts can cover ranges with one file when many weights are needed. 4) Wire it maintainably: expose the font as a CSS variable in the layout so styles reference var(--font-body) instead of hardcoding family names in many places. 5) If unsure which weights the design uses, check the actual styles first instead of importing everything. Only add the font once the loading path, weights, and application point are decided, and explain why this setup avoids both the external request and the layout shift — not just that the font 'shows up'.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #509\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}