___ _ ___ ___ _ | _ (_)__ ___/ __| _ \/_\ | _/ / _/ _ \__ \ _/ _ \ |_| |_\__\___/___/_|/_/ \_\ A PicoSSG tool

Section

PicoSPA provides GitHub-style anchor links for section headings, adding clickable # links that appear on hover.
Try it: hover over any heading above or below the # that appears is generated by PicoSPA after page load.

How To Use

Add the script to your page:

<script src="https://cdn.jsdelivr.net/npm/@pic0/spa@2026.1.12/_dist/picospa.min.js"></script>
<script>
  picospa.section.addAnchors();
</script>

This will automatically:

Important: Call addAnchors() or addIds() immediately after page load to ensure URLs with hash fragments (e.g., page.html#section-my-heading) can jump to the correct heading when the page loads.

Individual Functions

Add IDs Only

If you want to add IDs without anchor links, use:

picospa.section.addIds();
// Or with custom prefix
picospa.section.addIds({prefix: 'my-prefix'}); // The default prefix is 'section'.

Adds auto-generated IDs to all headings based on their text content.

Add Single ID

const heading = document.querySelector('h2');
picospa.section.addId({node: heading});
// Or with custom prefix
picospa.section.addId({node: heading, prefix: 'my-prefix'});

Adds an ID to a specific heading element.

Add Single Anchor

const heading = document.querySelector('h2');
picospa.section.addAnchor({ndoe: heading});

Adds an anchor link to a specific heading. This automatically calls addId() first if the heading doesn't have an ID.

Generated IDs

IDs are created by converting heading text to slugs:

Customization

You can customize the constants defined in the module:

// Customize the ID prefix (default: 'section')
picospa.section.ID_PREFIX = 'my-section';

// Customize the anchor text (default: '#')
picospa.section.ANCHOR_TEXT = 'ΒΆ';

// Customize the flag name that is being set in the `data-*` attribute of the anchor link, to manage the PicoSPA event handler.
picospa.section.HAS_SECTION_ANCHOR_FLAG_NAME = 'myCustomFlag';

Styling

The anchor links are positioned absolutely and styled with: