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.
The link
Give the section an id and wrap the heading's text in a link to it. A
heading whose only content is a link to a # keeps its heading colour, and a
# appears beside it on hover and on keyboard focus to show that it is a
link. Click a heading on this page and the address bar holds a link straight to it.
Install
Download the stylesheet and link it from the page's head.
<section id="install">
<h3><a href="#install">Install</a></h3>
<p>Download the stylesheet and link it from the page's head.</p>
</section>
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>
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.