Fylgja Heading Group
A heading group pairs a heading with a short eyebrow above it, a subtitle below it,
or both. It is built on the native <hgroup>, which keeps the extra lines tied to
the heading without adding them to the page outline.
Preview
Release notes
Fylgja 3.0 is here
Smaller, faster, and built on native CSS features.
<hgroup>
<p>Release notes</p>
<h2>Fylgja 3.0 is here</h2>
<p>Smaller, faster, and built on native CSS features.</p>
</hgroup>hgroup {
> p:has(+ :is(h1, h2, h3, h4, h5, h6)) {
margin-block-end: 0.5em;
color: color-mix(in oklab, var(--brand) 60%, var(--root-fg));
font-size: 0.875em;
font-weight: 600;
letter-spacing: 0.05em;
text-transform: uppercase;
}
> :is(h1, h2, h3, h4, h5, h6) ~ p {
margin-block-start: 0.5em;
color: color-mix(in oklab, var(--root-fg) 70%, var(--root-bg));
font-size: var(--lead-size, large);
}
}
Usage
- Wrap one heading and its paragraphs in an
<hgroup>. Base already removes the margins between them. - A
<p>before the heading becomes the eyebrow, a small uppercase line in the brand color. - A
<p>after the heading becomes the subtitle, in a larger and muted text. - The CSS selects the parts by their position, so the markup stays classless.
Anatomy
| Part | Responsibility |
|---|---|
<hgroup> |
Groups the heading with its eyebrow and subtitle. |
<p> before heading |
The eyebrow. A short label for the section, such as a category. |
<h1> to <h6> |
The heading itself, and the only part in the page outline. |
<p> after heading |
The subtitle. One sentence that expands on the heading. |
Accessibility
- Only the heading appears in the outline and in a screen reader’s list of headings. The paragraphs are read as normal text.
- Screen readers read the hgroup in source order, so the eyebrow is announced before the heading. Keep it short, so it does not delay the heading.
- Pick the heading level for its place in the page, not for its size.
Variants
Subtitle only
Pricing
One plan for every project, free and open source.
<hgroup>
<h2>Pricing</h2>
<p>One plan for every project, free and open source.</p>
</hgroup>Eyebrow only
Step 2 of 4
Choose your plan
<hgroup>
<p>Step 2 of 4</p>
<h2>Choose your plan</h2>
</hgroup>Centered
Add text-center to the hgroup to center all its parts.
Testimonials
Loved by developers
What people say after switching to Fylgja.
<hgroup class="text-center">
<p>Testimonials</p>
<h2>Loved by developers</h2>
<p>What people say after switching to Fylgja.</p>
</hgroup>Related: Heading Underline, Heading HR, CTA Banner.
FAQ
Why an hgroup and not a div?
HTML defines the paragraphs in an hgroup as part of the heading, which a div cannot express. The subtitle and eyebrow are not headings of their own, so they stay out of the page outline. Screen readers announce little extra for it, so the win is mostly in clean, meaningful markup.
Should the subtitle be a second heading?
No. A subtitle is not a new section, so an h3 below an h2 would add a false level to the outline. Use a paragraph inside the hgroup.
How does the CSS tell the eyebrow and the subtitle apart?
By position. A paragraph directly before the heading is the eyebrow, and a paragraph after the heading is the subtitle, so the markup needs no classes.