Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A GitHub Pages compatible Liquid snippet that adds anchor links to Jekyll headings without JavaScript or plugins.
Jekyll Anchor Headings is a pure Liquid include for Jekyll static sites that automatically injects anchor links into heading elements (h1 through h6) so every section has a deep-linkable URL, with no JavaScript and no custom plug-ins required.
Jekyll Anchor Headings is a single-file Liquid snippet that takes your page's compiled HTML (the markdown rendered by kramdown) as the html parameter and returns that same HTML with anchor <a> tags inserted into or before each heading. It runs entirely during Jekyll's build step, meaning the anchors are baked into the static files your server delivers. The project is developed by allejo as part of his "Pure Liquid" series, distributed under the MIT license.
beforeHeading, headerAttrs, anchorAttrs, anchorBody, anchorClass, anchorTitle, h_min, h_max, bodyPrefix, bodySuffix, and generateId, plus the required html.%heading% and %html_id% inside attribute and body strings to inject the heading text or generated ID dynamically.--profile reported 0.695 seconds for 193 includes totaling 1667.96K bytes.span containing "link") and set anchorAttrs with accessible attributes.anchor_headings.html from the latest release or the master branch._includes directory.{{ content }} with the include tag {% include anchor_headings.html html=content anchorBody="#" %}.h_min (default 1) and h_max (default 6).Yes, the snippet is open source under the MIT license and can be redistributed freely.
Yes. GitHub Pages cannot run custom Jekyll plugins, and this snippet uses only stock Liquid, so it's fully compatible with GitHub Pages builds.
Leave anchorBody empty and use the CSS content property on the anchor's ::before pseudo-element, or pass HTML to anchorBody (e.g., a span with a sr-only label).
Because the snippet operates on the layout it's included in; if both a parent and child layout include it, headings get two anchors. Use it in only one layout per page.
Set h_min and h_max to restrict the heading levels. For example, h_min=2 and h_max=4 would anchor only h2, h3, and h4 headings.
