shadcn has a heading font. Here is what it is for.
The font-heading class on shadcn's card and dialog titles, what sets it, and why it is not the place for your display face.
Audrey KlammershadcnTypography
I reinstalled shadcn's components this week and one class was new on a handful
of titles: font-heading. It is easy to miss, and it changes how you set a
second typeface in a shadcn project.
What it is
font-heading is a Tailwind utility backed by a theme variable,
--font-heading. shadcn defines it beside --font-sans and --font-mono
(globals.css, lines 47 to 49):
@theme inline {
--font-sans: var(--font-sans);
--font-heading: var(--font-heading);
--font-mono: var(--font-mono);
}
The preset builder has a matching option, fontHeading. Every preset the
CLI ships sets it to inherit, which means the heading font is the body
font, except Sera, which sets Playfair Display
(defaults.ts, line 103).
In the others, nothing looks different out of the box.
Where it shows up
Only on small component titles:
CardTitleDialogTitleAlertDialogTitleSheetTitleDrawerTitleEmptyTitle- the title in Questionnaire
In shadcn's own source the class is written cn-font-heading
(card.tsx, line 36); the
CLI turns it into font-heading when it installs the part.
Page headings are not part of it. An h1 you write yourself has no
font-heading class unless you add one.
What shadcn says it is for
Their design system guide is direct about it:
--font-headingstyles small component titles (CardTitle,DialogTitle,SheetTitle). Point it at the display face only when that face reads well at 16px. Otherwise keep it on the sans and use display tokens for page headings.
So there are two jobs, and they get two variables. One is for the short titles inside components. The other, which you define yourself, is for the large headings on a page.
Setting it
Load the face and give it the variable name. With next/font:
import { Bricolage_Grotesque, Geist } from "next/font/google"
const fontSans = Geist({ subsets: ["latin"], variable: "--font-sans" })
const fontHeading = Bricolage_Grotesque({
subsets: ["latin"],
variable: "--font-heading",
})
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en" className={`${fontSans.variable} ${fontHeading.variable}`}>
<body>{children}</body>
</html>
)
}
Every card, dialog, sheet and drawer title now uses it. You did not touch a component file.
The mistake to avoid
A display face is drawn for large sizes. Set at 16px in a card title it often
looks thin, cramped or fussy. If your second typeface is a serif or anything
with strong character, keep --font-heading on the sans and give the display
face its own variable for page headings.
How 01orbital handles it
The kit keeps the same two layers. Stock titles follow --font-heading, which
follows the body face unless a theme changes it. Section headings use the
kit's own font-display, and a block opts in to a display face where it wants
one:
<section className="[--font-display:var(--font-serif)]">
<Heading>A serif headline, in this section only.</Heading>
</section>
The card titles inside that section stay in the body face.