Heading anchors

A heading anchor makes a heading into a link to its own section, so a reader can copy a link that opens the page right there. The heading's text is the link, so the link's name is simply the heading. No class is needed. Point at a heading on this page to see the mark.

Why the whole text

Many sites add a separate small # or chain icon beside the heading as the link. A screen reader then meets a string of links all called "#" or "link", with nothing to tell them apart. Making the heading's own text the link gives every anchor a clear, different name and adds nothing extra to the Tab order. The # here is only drawn by the stylesheet and is never read out.

Any level

It works on headings from h2 to h6. The page's h1 is the top of the page, which needs no anchor.

A subsection

An h3 anchor, inside the section above.

A detail

An h4 anchor, one level further down.

<section id="a-subsection">
  <h3><a href="#a-subsection">A subsection</a></h3>
  <p>An <code>h3</code> anchor, inside the section above.</p>
  <section id="a-detail">
    <h4><a href="#a-detail">A detail</a></h4>
    <p>An <code>h4</code> anchor, one level further down.</p>
  </section>
</section>
Anchors on an h3 and an h4

Where it lands

Opening a link to a section scrolls the section to just below the sticky header, so the heading is never hidden under it. The page keeps a margin at the top the size of the header for exactly this.