headings
Heading elements define the hierarchical structure of a document. Six levels from h1 (most important) to h6 (least), used for titles, sections, and content organization.
Heading Scale
VB provides six heading levels, each mapped to a font-size token. All headings share font-weight: 600, text-wrap: balance, lining numerals, and disabled hyphenation.
<h1>Heading Level 1</h1><h2>Heading Level 2</h2><h3>Heading Level 3</h3><h4>Heading Level 4</h4><h5>Heading Level 5</h5><h6>Heading Level 6</h6>
| Element | Font Size Token | Computed | Letter Spacing |
|---|---|---|---|
<h1> |
--font-size-4xl |
2.25rem (36px) | -0.025em |
<h2> |
--font-size-3xl |
1.875rem (30px) | -0.01em |
<h3> |
--font-size-2xl |
1.5rem (24px) | normal |
<h4> |
--font-size-xl |
1.25rem (20px) | normal |
<h5> |
--font-size-lg |
1.125rem (18px) | normal |
<h6> |
--font-size-md |
1rem (16px) | normal |
h1 and h2 get tighter letter-spacing (tracking) because large text has more apparent whitespace between characters. h6 uses font-weight: 700 instead of 600 for visual differentiation at body-text size.
Document Hierarchy
Headings create the document outline. Use them in order without skipping levels — an <h3> should always follow an <h2>, never an <h1> directly.
<article> <h1>The History of Typography</h1> <p>Typography has evolved over centuries...</p> <h2>Early Printing</h2> <p>Gutenberg's movable type press...</p> <h3>The Gutenberg Bible</h3> <p>Printed around 1455...</p> <h2>Modern Typography</h2> <p>The digital revolution brought new possibilities...</p> <h3>Variable Fonts</h3> <p>A single font file with multiple variations...</p> <h3>System Font Stacks</h3> <p>Using native fonts for performance...</p></article>
Rule of thumb: Each page should have exactly one <h1>. Sections use <h2>. Subsections use <h3>. Levels 4–6 are for fine-grained structure within long documents.
Heading Links
Wrap content in the <heading-links> web component to add hover-reveal anchor links to headings. It auto-generates id attributes from heading text and supports click-to-copy URL.
<heading-links> <h2>Getting Started</h2> <p>Install Vanilla Breeze and start building.</p> <h3>Installation</h3> <p>Add the stylesheet and script to your page.</p> <h3>Configuration</h3> <p>Customize tokens and theme settings.</p> <h2>Components</h2> <p>Explore the available components.</p></heading-links>
By default, <heading-links> processes h2 and h3. Use levels="h2,h3,h4" to include additional levels.
Table of Contents
The <page-toc> web component auto-generates a table of contents from headings with scroll-spy highlighting. It pairs with <heading-links> which provides the heading IDs.
<page-toc></page-toc> <!-- Auto-generates a table of contents from h2/h3 headings within <main>. Uses IntersectionObserver for scroll-spy highlighting. -->
Both components default to h2 and h3 because h1 is the page title (not a section) and h4–h6 are too granular for most navigation.
Theme Ornament Hooks
Themes can add decorative glyphs before or after headings using CSS custom properties. These tokens are theme-controlled — the base VB stylesheet sets them to none.
/* Theme file — add decorative glyphs before headings */:root { --heading-ornament-before: "§ ";} /* Per-level overrides */:root { --h1-ornament-before: "❧ "; --h2-ornament-before: "§ "; --h3-ornament-before: "› ";}
| Token | Scope |
|---|---|
--heading-ornament-before |
All headings (h1–h6) |
--heading-ornament-after |
All headings (h1–h6) |
--h1-ornament-before / after |
h1 only (overrides global) |
--h2-ornament-before / after |
h2 only (overrides global) |
--h3-ornament-before / after |
h3 only (overrides global) |
Typography Features
Headings include several typographic refinements applied automatically:
font-variant-numeric: lining-nums— Numbers align with capital letters rather than descending like oldstyle numeralshyphens: none— Headings are never hyphenated, even when the parent hashyphens: autotext-wrap: balance— Text distributes evenly across lines, preventing short orphan linesletter-spacing— h1 and h2 get tighter tracking at large sizes for better visual density
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: var(--line-height-tight); text-wrap: balance; font-variant-numeric: lining-nums; hyphens: none;} h1 { font-size: var(--font-size-4xl); letter-spacing: var(--letter-spacing-tight);}h2 { font-size: var(--font-size-3xl); letter-spacing: -0.01em;}h3 { font-size: var(--font-size-2xl); }h4 { font-size: var(--font-size-xl); }h5 { font-size: var(--font-size-lg); }h6 { font-size: var(--font-size-md); font-weight: 700; }
Heading Groups
Use <hgroup> to pair a heading with a subtitle, eyebrow label, byline, or other secondary text. Only the heading contributes to the document outline.
<hgroup> <h2>Progressive Enhancement</h2> <p>Building resilient interfaces that work for everyone.</p></hgroup> <!-- Variants: .eyebrow, .byline, .section-header, .display, .centered, .reversed, .divided -->
See the hgroup documentation for all variants including .eyebrow, .byline, .section-header, and .display.
Accessibility
- One h1 per page — The page title. Screen readers use it as the primary landmark
- Sequential levels — Never skip levels (h1 → h3). Screen reader users navigate by heading level
- Descriptive text — Headings should summarize the section content. Avoid generic text like "Section 1"
- Don't use for styling — Choose heading level by hierarchy, not visual size. Use CSS to adjust appearance
- heading-links — The anchor links added by
<heading-links>include descriptivearia-labelattributes - Heading count — Screen readers can list all headings on a page. Well-structured headings serve as an alternative navigation method
Related
<hgroup>— Pair headings with subtitles, eyebrow labels, or bylines<heading-links>— Add anchor links to headings with auto-generated IDs<page-toc>— Auto-generate table of contents from headings with scroll-spy<article>— Self-contained content that typically starts with a heading<section>— Thematic grouping identified by its heading- Typography — Lining numerals, letter-spacing, and other typographic refinements