Guides

Fonts04

The fonts come with the package, so there's nothing to load. When you want your own, three variables change them everywhere.

Built in

Each personality has a display font for headings, buttons and labels, and a body font for running text. They're bundled with Plonk as woff2 files and declared in theme.css.

PersonalityDisplayBody
StickerBaloo 2Nunito
RetroTiny5IBM Plex Mono
ComicBangersKalam
ArcadeBungeeRubik

You don't pay for what you don't use. Browsers only download a font when something on the page is drawn with it, so an app that only uses Sticker never fetches Retro's pixel font.

Every font covers Latin and Latin Extended, including Turkish, Polish, Czech and other accented alphabets. All of them are licensed under the SIL Open Font License; the license files ship next to the fonts.

Use your own

Fonts are tokens like everything else:

  • --plonk-font-display for headings, buttons and labels
  • --plonk-font-body for text
  • --plonk-font-mono for code and keyboard keys
Fonts · Your ownLive

Quarterly report

Same component, your typefaces.

TSX
import { Button, Card, PlonkProvider, usePersonality } from "plonk-ui";

export default function CustomFont() {
  const personality = usePersonality();
  return (
    <PlonkProvider
      personality={personality}
      style={{
        "--plonk-font-display": "Georgia, 'Times New Roman', serif",
        "--plonk-font-body": "system-ui, sans-serif",
        "--plonk-font-display-case": "none",
      }}
    >
      <Card title="Quarterly report" className="w-72 max-w-full">
        <div className="flex flex-col items-start gap-4">
          <p>Same component, your typefaces.</p>
          <Button>Download PDF</Button>
        </div>
      </Card>
    </PlonkProvider>
  );
}

For every personality

CSS
:root,
[data-plonk-personality] {
  --plonk-font-display: "Inter", system-ui, sans-serif;
  --plonk-font-body: "Inter", system-ui, sans-serif;
}

For one personality

CSS
[data-plonk-personality="retro"] {
  --plonk-font-body: "JetBrains Mono", ui-monospace, monospace;
}

For one part of the page

TSX
<PlonkProvider
  personality="sticker"
  style={{ "--plonk-font-display": "Georgia, serif" }}
>
  <Article />
</PlonkProvider>;

Loading the font

Plonk only points at a font name; loading it is up to you. With Next.js, next/font gives you a CSS variable to hand over:

// app/layout.tsx
import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en" className={inter.variable}>
      <body>
        <PlonkProvider style={{ "--plonk-font-body": "var(--font-inter)" }}>
          {children}
        </PlonkProvider>
      </body>
    </html>
  );
}

Anywhere else, a regular @font-face rule or a Google Fonts link works.

Fonts with only capitals

Comic's Bangers and Arcade's Bungee only draw capital letters. Plonk sets their text to text-transform: uppercase so the browser picks the right capital for the language: in Turkish, i becomes İ, not I. That only works when the page knows its language, which is one reason to set locale on the provider.

If you bring your own capitals-only font, tell Plonk:

CSS
[data-plonk-personality="sticker"] {
  --plonk-font-display: "Bebas Neue", sans-serif;
  --plonk-font-display-case: uppercase;
}

The reverse also works: give Comic or Arcade a font with lowercase letters and set --plonk-font-display-case: none.