Component Library

← Back to gallery

Inline glossary jump index in HTML, CSS and vanilla JS

A copy-paste Inline glossary jump index in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Navigation · Tags: toc, in-page, anchors, headings, navigation

Live preview

Source (copy-ready)

<section class="dcl-table-of-contents-inline-index" data-dcl-scheme="light">
<h2>Inline glossary jump index</h2>
<nav aria-label="Quick index" ><ul data-line><li><a href="#dcl-table-of-contents-inline-index-prep">Prepare your equipment</a></li><li><a href="#dcl-table-of-contents-inline-index-care">Clean and check</a></li><li><a href="#dcl-table-of-contents-inline-index-store">Pack for storage</a></li></ul></nav><section data-chapter><h3 id="dcl-table-of-contents-inline-index-prep" tabindex="-1">Prepare your equipment</h3><p>Gather the parts and inspect the storage case.</p></section><section data-chapter><h3 id="dcl-table-of-contents-inline-index-care" tabindex="-1">Clean and check</h3><p>Clean surfaces gently and let them dry before inspection.</p></section><section data-chapter><h3 id="dcl-table-of-contents-inline-index-store" tabindex="-1">Pack for storage</h3><p>Store small parts together in their labelled pouch.</p></section>
<script>
(() => {
const root = document.currentScript.closest('.dcl-table-of-contents-inline-index');
const instance = Array.from(document.getElementsByClassName('dcl-table-of-contents-inline-index')).indexOf(root);
if (instance) {
  const suffix = '--' + instance;
  const attributes = ['id','aria-labelledby','aria-describedby','aria-controls','for','name','popovertarget'];
  for (const element of root.querySelectorAll('*')) {
    for (const attr of attributes) {
      if (element.hasAttribute(attr)) element.setAttribute(attr, element.getAttribute(attr).split(/\s+/).map(value => value + suffix).join(' '));
    }
    const href = element.getAttribute('href');
    if (href && href.startsWith('#')) element.setAttribute('href', href + suffix);
  }
}
const media = matchMedia('(prefers-color-scheme: dark)');
const theme = () => { root.dataset.dclScheme = media.matches ? 'dark' : 'light'; };
media.addEventListener('change', theme);
theme();
root.addEventListener('click', event => {
  const anchor = event.target.closest('a[href]');
  if (!anchor || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
  const href = anchor.getAttribute('href');
  if (!href.startsWith('#')) return;
  const target = root.querySelector(href);
  if (!target) return;
  event.preventDefault();
  target.focus({preventScroll: true});
  target.scrollIntoView({block: 'nearest'});
});

})();
</script>
</section>
<style>
.dcl-table-of-contents-inline-index { box-sizing: border-box; max-width: 58rem; padding: clamp(.75rem, 3vw, 1.5rem); border: 1px solid; border-radius: .75rem; font: 1rem/1.5 system-ui,sans-serif; overflow-wrap: anywhere; }
.dcl-table-of-contents-inline-index *, .dcl-table-of-contents-inline-index *::before, .dcl-table-of-contents-inline-index *::after { box-sizing: border-box; }
.dcl-table-of-contents-inline-index h2, .dcl-table-of-contents-inline-index h3, .dcl-table-of-contents-inline-index p, .dcl-table-of-contents-inline-index ul, .dcl-table-of-contents-inline-index ol, .dcl-table-of-contents-inline-index figure { margin: 0; }
.dcl-table-of-contents-inline-index h2 { font-size: 1.25rem; margin-bottom: .875rem; }
.dcl-table-of-contents-inline-index h3 { font-size: 1rem; }
.dcl-table-of-contents-inline-index li + li, .dcl-table-of-contents-inline-index p + p { margin-top: .375rem; }
.dcl-table-of-contents-inline-index ul, .dcl-table-of-contents-inline-index ol { padding-inline-start: 1.35rem; }
.dcl-table-of-contents-inline-index a { text-underline-offset: .18em; }
.dcl-table-of-contents-inline-index a:hover { text-decoration-thickness: .18em; }
.dcl-table-of-contents-inline-index :focus-visible { outline-style: solid; outline-width: 3px; outline-offset: 2px; }
.dcl-table-of-contents-inline-index button, .dcl-table-of-contents-inline-index summary, .dcl-table-of-contents-inline-index input, .dcl-table-of-contents-inline-index select { font: inherit; max-width: 100%; }
.dcl-table-of-contents-inline-index button, .dcl-table-of-contents-inline-index input, .dcl-table-of-contents-inline-index select { padding: .35rem .65rem; border: 1px solid; border-radius: .375rem; }
.dcl-table-of-contents-inline-index button, .dcl-table-of-contents-inline-index summary, .dcl-table-of-contents-inline-index select { cursor: pointer; }
.dcl-table-of-contents-inline-index button:active, .dcl-table-of-contents-inline-index summary:active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-table-of-contents-inline-index button:disabled, .dcl-table-of-contents-inline-index button[aria-disabled="true"] { cursor: not-allowed; border-style: dashed; }
.dcl-table-of-contents-inline-index [hidden] { display: none !important; }
.dcl-table-of-contents-inline-index [data-line], .dcl-table-of-contents-inline-index [data-actions] { display: flex; gap: .5rem .75rem; align-items: center; flex-wrap: wrap; }
.dcl-table-of-contents-inline-index [data-grid] { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,9rem),1fr)); gap: .75rem; }
.dcl-table-of-contents-inline-index [data-stack], .dcl-table-of-contents-inline-index [data-targets] { display: grid; gap: .75rem; }
.dcl-table-of-contents-inline-index [data-targets] { border-top: 1px solid; padding-top: .75rem; margin-top: .75rem; }
.dcl-table-of-contents-inline-index [data-card], .dcl-table-of-contents-inline-index [data-status], .dcl-table-of-contents-inline-index [data-panel] { padding: .75rem; border: 1px solid; border-radius: .5rem; }
.dcl-table-of-contents-inline-index [data-status] { margin-top: .75rem; }
.dcl-table-of-contents-inline-index [data-status]:empty { border-width: 0; padding: 0; margin: 0; }
.dcl-table-of-contents-inline-index [aria-current] { font-weight: 750; }
.dcl-table-of-contents-inline-index dialog, .dcl-table-of-contents-inline-index [popover] { max-height: calc(100dvh - 2rem); max-width: calc(100% - 2rem); width: min(36rem,100%); border: 1px solid; border-radius: .75rem; padding: 1rem; overflow: auto; }
.dcl-table-of-contents-inline-index dialog h3, .dcl-table-of-contents-inline-index [popover] h3 { margin-bottom: .5rem; }
.dcl-table-of-contents-inline-index dialog [data-actions], .dcl-table-of-contents-inline-index [popover] [data-actions] { margin-top: .75rem; }
.dcl-table-of-contents-inline-index svg { display: block; width: 100%; height: auto; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="light"] { color: #11292f; background-color: #ffffff; border-color: #697f84; color-scheme: light; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="light"] a { color: #005c62; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="light"] button, .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] input, .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] select, .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] summary, .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] [data-card], .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] [data-status], .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] [data-panel] { color: #11292f; background-color: #e4edef; border-color: #697f84; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="light"] button:hover, .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] summary:hover { color: #ffffff; background-color: #00535a; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="light"] dialog, .dcl-table-of-contents-inline-index[data-dcl-scheme="light"] [popover] { color: #11292f; background-color: #ffffff; border-color: #697f84; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="light"] :focus-visible { outline-color: #005c62; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; border-color: #839fa5; color-scheme: dark; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] a { color: #8fe1da; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] button, .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] input, .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] select, .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] summary, .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] [data-card], .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] [data-status], .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] [data-panel] { color: #eff8f9; background-color: #1c3c44; border-color: #839fa5; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] button:hover, .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] summary:hover { color: #11292f; background-color: #8fe1da; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] dialog, .dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] [popover] { color: #eff8f9; background-color: #142f36; border-color: #839fa5; }
.dcl-table-of-contents-inline-index[data-dcl-scheme="dark"] :focus-visible { outline-color: #8fe1da; }
.dcl-table-of-contents-inline-index nav ul { list-style: none; padding: 0 0 .75rem; border-bottom: 1px solid; margin-bottom: .75rem; } .dcl-table-of-contents-inline-index nav li { margin: 0; } .dcl-table-of-contents-inline-index nav a { display: block; padding: .2rem .45rem; border: 1px solid; border-radius: 1rem; }
</style>

When to use

Compact wrapping line of short local jumps for a glossary or reference, rather than a vertical sidebar. Replace the example content and wire the controls or destination IDs to your own screen.

Avoid

Don't pack lengthy headings into the row.

Accessibility

Keyboard focus is visibly outlined. Preserve link boundaries and visible focus at wrap points. The main text contrast is 15.2:1/13.1:1 in light/dark mode, respectively.

Was this useful? Send feedback.