Built-in automatic self-hosting for any font file with optimal loading and zero layout shift
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Google Fonts integration providing access to 1625+ Google Font families with automatic optimization, self-hosting, and zero layout shift. Each font is available as a named export with full TypeScript support.
Every Google Font is available as a named export function. Font names are transformed from their Google Fonts names by replacing spaces and special characters with underscores.
/**
* Generic Google Font function signature
* @param options - Font configuration options
* @returns Font object with className, style, and optional variable property
*/
function GoogleFont<T extends CssVariable | undefined = undefined>(options?: {
weight?: string | string[] | 'variable';
style?: string | string[];
display?: Display;
variable?: T;
preload?: boolean;
fallback?: string[];
adjustFontFallback?: boolean;
subsets?: string[];
}): T extends undefined ? NextFont : NextFontWithVariable;Popular Font Examples:
// Inter - Variable font
function Inter<T extends CssVariable | undefined = undefined>(options?: {
weight?: 'variable' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | Array<'100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'>;
style?: 'normal' | Array<'normal'>;
display?: Display;
variable?: T;
preload?: boolean;
fallback?: string[];
adjustFontFallback?: boolean;
subsets?: Array<'cyrillic' | 'cyrillic-ext' | 'greek' | 'greek-ext' | 'latin' | 'latin-ext' | 'vietnamese'>;
}): T extends undefined ? NextFont : NextFontWithVariable;
// Roboto - Standard weights
function Roboto<T extends CssVariable | undefined = undefined>(options: {
weight: '100' | '300' | '400' | '500' | '700' | '900' | Array<'100' | '300' | '400' | '500' | '700' | '900'>;
style?: 'normal' | 'italic' | Array<'normal' | 'italic'>;
display?: Display;
variable?: T;
preload?: boolean;
fallback?: string[];
adjustFontFallback?: boolean;
subsets?: Array<'cyrillic' | 'cyrillic-ext' | 'greek' | 'greek-ext' | 'latin' | 'latin-ext' | 'vietnamese'>;
}): T extends undefined ? NextFont : NextFontWithVariable;
// Open_Sans - Variable font with named instance weights
function Open_Sans<T extends CssVariable | undefined = undefined>(options?: {
weight?: 'variable' | '300' | '400' | '500' | '600' | '700' | '800' | Array<'300' | '400' | '500' | '600' | '700' | '800'>;
style?: 'normal' | 'italic' | Array<'normal' | 'italic'>;
display?: Display;
variable?: T;
preload?: boolean;
fallback?: string[];
adjustFontFallback?: boolean;
subsets?: Array<'cyrillic' | 'cyrillic-ext' | 'greek' | 'greek-ext' | 'hebrew' | 'latin' | 'latin-ext' | 'math' | 'symbols' | 'vietnamese'>;
}): T extends undefined ? NextFont : NextFontWithVariable;weight?: string | string[] | 'variable';'400', '700' - Loads specific font weight['400', '700'] - Loads multiple weights'variable' - Loads the variable font version if availablestyle?: string | string[];'normal', 'italic' - Loads specific font style['normal', 'italic'] - Loads multiple styles'normal' if not specifieddisplay?: Display;Controls the CSS font-display property:
variable?: T;Creates a CSS custom property for the font family:
const inter = Inter({
subsets: ['latin'],
variable: '--font-inter',
});
// Usage in CSS
// font-family: var(--font-inter);preload?: boolean;Controls whether font files are preloaded:
<link rel="preload"> for faster font loadingsubsets?: string[];Specifies which font subsets to load. Common subsets include:
fallback?: string[];
adjustFontFallback?: boolean;import { Inter } from "@next/font/google";
const inter = Inter({
subsets: ['latin'],
});
export default function Page() {
return (
<div className={inter.className}>
<p>This text uses Inter font</p>
</div>
);
}import { Inter } from "@next/font/google";
const inter = Inter({
subsets: ['latin'],
variable: '--font-inter',
});
export default function RootLayout({ children }) {
return (
<html lang="en" className={inter.variable}>
<body>{children}</body>
</html>
);
}import { Roboto } from "@next/font/google";
const roboto = Roboto({
weight: ['300', '400', '700'],
style: ['normal', 'italic'],
subsets: ['latin'],
display: 'swap',
});import { Playfair_Display } from "@next/font/google";
const playfair = Playfair_Display({
weight: ['400', '700'],
subsets: ['latin'],
fallback: ['Georgia', 'serif'],
adjustFontFallback: true,
});import { Inter } from "@next/font/google";
const inter = Inter({
subsets: ['latin'],
preload: true, // Preload for above-the-fold content
});Google Font names are transformed for JavaScript compatibility:
Open_SansSource_Sans_ProJosefin_SansRoboto_MonoThe package includes 1625+ Google Fonts. Some popular examples:
Inter - Modern variable font, excellent for UIRoboto - Google's signature fontOpen_Sans - Friendly, readable fontLato - Humanist sans-serifMontserrat - Geometric sans-serifPlayfair_Display - High-contrast serifMerriweather - Designed for screensLora - Brush-style serifSource_Serif_Pro - Adobe's serif fontFira_Code - With programming ligaturesSource_Code_Pro - Adobe's monospace fontJetBrains_Mono - Designed for developersRoboto_Mono - Google's monospace fontOswald - Gothic-style display fontBebas_Neue - Condensed display fontRighteous - Casual display font