heading-anchors

<heading-anchors> Web Component

A web component to add and position sibling anchor links for heading elements (h1h6) when they have an id attribute.

Inspired by David Darnes’ <heading-anchors>.

Installation

npm install @zachleat/heading-anchors

Include the heading-anchors.js file on your web site (via <script type="module">) and use <heading-anchors>.

Features

Options

Prior Art

Advanced

Eliminate Layout Shift

(Optional) There is a small layout shift by the addition of the # character. Add this CSS to make room for this pre-component definition:

heading-anchors:not(:defined) :is(h2,h3,h4,h5,h6):after {
	content: "#";
	padding: 0 .25em;
	opacity: 0;
}