---
title: "Heading Anchor"
description: "Heading Anchor component - a quiet § or # permalink hanging in front of any heading, or before or after its text, no JavaScript."
slug: "heading-anchor"
---

import { DocPage, PageHeader, SkillPanel, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="heading-anchor" title="Heading Anchor" component="heading-anchor">
  A quiet § (or #) permalink on any heading - hanging in front of it and shown on hover by default, or inline before or after its text. A copyable deep link with no JavaScript.
</PageHeader>

<SkillPanel component="heading-anchor">
  <SkillField label="Native basis">
    <SkillText><code>&lt;a&gt;</code> element containing the section glyph §, placed as the first or last child of the heading it links to. The browser's native fragment navigation does the work.</SkillText>
  </SkillField>
  <SkillField label="Web Platform APIs">
    <SkillRow>
      <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a" title="native anchor with href"><code>&lt;a&gt;</code></ApiPill>
      <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/:target" title="native deep links, no JS scroll logic"><code>:target</code></ApiPill>
      <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-label" title="the glyph alone is not a name"><code>aria-label</code></ApiPill>
    </SkillRow>
  </SkillField>
  <SkillField label="Classes">
    <SkillRow>
      <code>.heading-anchor</code>
    </SkillRow>
  </SkillField>
  <SkillField label="Placements (data-placement)">
    <SkillGrid>
      <Variant name="front" description="the default - hangs in front of the heading, shown on hover, focus and target" />
      <Variant name="before" description="inline in front of the text, always shown" />
      <Variant name="after" description="trailing the text, always shown" />
    </SkillGrid>
  </SkillField>
  <SkillField label="Sizes (data-size)">
    <SkillGrid>
      <Variant name="xs" description="0.75rem - fine print, captions" />
      <Variant name="sm" description="0.875rem - small headings" />
      <Variant name="md" description="1rem - default heading size" />
      <Variant name="lg" description="1.125rem - section headings" />
      <Variant name="xl" description="1.25rem - page titles" />
    </SkillGrid>
  </SkillField>
</SkillPanel>

```html example label="Sizes" hint="data-size pins the glyph size explicitly; without it the glyph inherits the heading's own font size (recommended - it then tracks the heading automatically). The glyph always inherits the heading's font family - var(--font-sans), var(--font-serif) and var(--font-mono) all work."
<a class="heading-anchor" data-size="sm" data-placement="before" href="#intro" aria-label="Link to section: Intro">§</a>
```

```html example label="In front of the heading (default)" hint="Hover the heading: the glyph hangs in the gutter, so the heading's text keeps its own start edge. It also shows on keyboard focus and when the section is the address's target; on a touch screen it sits in front of the text instead. Leave about 1.5em of room at the heading's start."
<h3 id="tokens" style="padding-inline-start: 2rem">
  <a class="heading-anchor" href="#tokens" aria-label="Link to section: Tokens">§</a>
  Tokens
</h3>
```

```html example label="With # instead of §" hint="The glyph is the link's text - a hash reads as a permalink to readers who know it from GitHub and Markdown."
<h3 id="spacing" style="padding-inline-start: 2rem">
  <a class="heading-anchor" href="#spacing" aria-label="Link to section: Spacing">#</a>
  Spacing
</h3>
```

```html example label="Before the heading text" hint="data-placement=&quot;before&quot; puts the glyph inline in front of the text, always shown."
<h3 id="colors">
  <a class="heading-anchor" href="#colors" data-placement="before" aria-label="Link to section: Colors">§</a>
  Colors
</h3>
```

```html example label="After the heading text" hint="data-placement=&quot;after&quot; trails the text, always shown."
<h3 id="motion">
  Motion
  <a class="heading-anchor" href="#motion" data-placement="after" aria-label="Link to section: Motion">§</a>
</h3>
```

<SourceFiles component="heading-anchor" />

</DocPage>
