Next.js
Use Openbase with next/font: self-hosted, preloaded, no layout shift.
@openbase/fonts ships one next/font/local entry per family. Next.js self-hosts the files, preloads them and sizes a fallback so the page does not shift while they load.
npm install @openbase/fontsApp Router
import { OpenbaseSans } from "@openbase/fonts/next/sans";
import { OpenbaseMono } from "@openbase/fonts/next/mono";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" className={`${OpenbaseSans.variable} ${OpenbaseMono.variable}`}>
<body className={OpenbaseSans.className}>{children}</body>
</html>
);
}| Export | Entry point | CSS variable |
|---|---|---|
| OpenbaseSans | @openbase/fonts/next/sans | --font-openbase-sans |
| OpenbaseMono | @openbase/fonts/next/mono | --font-openbase-mono |
| OpenbaseDrawn | @openbase/fonts/next/drawn | --font-openbase-drawn |
@openbase/fonts/next exports all three for convenience.Variable fonts
Openbase Sans and Openbase Mono also come as variable fonts: one file per style holds every weight from 300 to 700, so font-weight: 450 works and a page that uses several weights loads one file instead of several.
import { OpenbaseSansVariable } from "@openbase/fonts/next/sans-variable";
import { OpenbaseMonoVariable } from "@openbase/fonts/next/mono-variable";
<html className={`${OpenbaseSansVariable.variable} ${OpenbaseMonoVariable.variable}`}>They set the same CSS variables as the static entries, so the rest of your CSS stays the same. Openbase Drawn is static only: its strokes are drawn separately for each weight.
Italics
Every entry includes the italics. Use font-style: italic (or Tailwind's italic), and <em> and <i> pick them up by themselves. Italics keep the upright widths, so switching to italic never reflows a line.
Pages Router
import type { AppProps } from "next/app";
import { OpenbaseSans } from "@openbase/fonts/next/sans";
export default function App({ Component, pageProps }: AppProps) {
return (
<main className={OpenbaseSans.className}>
<Component {...pageProps} />
</main>
);
}With Tailwind CSS
Point Tailwind's font tokens at the variables set on <html>:
@import "tailwindcss";
@theme inline {
--font-sans: var(--font-openbase-sans);
--font-mono: var(--font-openbase-mono);
--font-drawn: var(--font-openbase-drawn);
}Now font-sans, font-mono and font-drawn work as classes.
A drawn appearance
Because Openbase Drawn has Openbase Sans' metrics, a whole interface can switch between them with one attribute and nothing reflows:
html { font-family: var(--font-openbase-sans); }
html[data-appearance="drawn"] { font-family: var(--font-openbase-drawn); }