Interactive HTML sitemap: a lightweight static-sitemap enhancer, or an information-architecture tree with page-type badges, keyboard navigation and an SVG org-chart view.
Overview
The <site-map> component has two modes. The default, mode="nav-enhance", enhances a static HTML sitemap with current-page highlighting, auto-expanding the section containing the current page, and expand/collapse all controls. mode="ia-tree" turns a nested list into an interactive information-architecture tree with page-type badges and an optional SVG org-chart view. Without JavaScript, either sitemap is a fully functional nested list of links.
12345678910111213141516171819202122232425
<site-map> <nav aria-label="Full site map"> <ul> <li> <details> <summary><a href="/docs/">Documentation</a></summary> <ul> <li><a href="/docs/quick-start/">Quick Start</a></li> <li> <details> <summary><a href="/docs/elements/">Elements</a></summary> <ul> <li><a href="/docs/elements/native/">Native</a></li> <li><a href="/docs/elements/web-components/">Web Components</a></li> </ul> </details> </li> </ul> </details> </li> <li><a href="/about/">About</a></li> <li><a href="/blog/">Blog</a></li> </ul> </nav></site-map>
Attributes
| Attribute | Type | Default | Description |
current |
string |
window.location.pathname |
Pathname of the current page to highlight |
mode |
string |
"nav-enhance" |
"nav-enhance" or "ia-tree" (see IA tree mode) |
src |
string |
— |
URL to load sitemap data from as JSON. Strings render as text; only http(s), relative and fragment hrefs become link targets. |
title |
string |
— |
[ia-tree] Heading and tree name |
collapsed |
boolean |
— |
[ia-tree] Start with every node collapsed |
compact |
boolean |
— |
[ia-tree] Tighter spacing |
data-label-* |
string |
English |
[nav-enhance] UI string overrides: expand, collapse, controls |
data-view |
string |
— |
[ia-tree] "visual" renders an SVG org chart |
data-orientation |
string |
"vertical" |
[visual] "vertical" or "horizontal" |
data-detail |
number |
2 |
[visual] 0 shape, 1 title, 2 full, 3 full + status, 4 wireframe |
Current Page Highlighting
By default, the component uses window.location.pathname to detect the current page and highlight its link. Use current to override this, for example in server-rendered or testing contexts.
123
<site-map current="/docs/elements/web-components/"> </site-map>
The matching link receives an aria-current="page" attribute and a visual highlight. All ancestor <details> elements are automatically expanded to reveal it.
HTML Structure
The sitemap uses nested <details> and <summary> elements for collapsible sections, wrapped in a <nav> landmark.
123456789101112131415
<nav aria-label="Full site map"> <ul> <li> <details> <summary><a href="/section/">Section Title</a></summary> <ul> <li><a href="/section/page/">Page</a></li> </ul> </details> </li> <li><a href="/standalone/">Standalone Page</a></li> </ul></nav>
Structure Rules
- Wrap the entire sitemap in
<nav aria-label="Full site map">
- Use
<details>/<summary> for sections with children
- Place the section link inside
<summary>
- Child pages go in a nested
<ul> inside the <details>
- Leaf pages are simple
<li><a> elements
Outline styling
The nav renders as a quiet outline: plain text links, a hairline down each nested level, and <details> branches that read as rows with a leading arrow. The expand/collapse-all buttons sit directly above it, below any heading and intro. Outside a <site-map>, add data-sitemap to the nav for the same styling.
Four optional hooks shape a large sitemap:
data-sitemap-section on a top-level <li> makes it a headed block: an <h2> followed by a <ul> whose items (the groups) sit side by side. A group that holds <details> takes the full row.
data-sitemap-leaves on a <ul> flows a long run of leaf pages into columns.
data-sitemap-label on a <span> labels a branch that has no page of its own. A <small> inside an <h2> or <summary> is a muted page count.
data-sitemap-updated on a <small> is a muted note of when a page, branch or section last changed.
12345678910111213141516171819
<nav aria-label="Full site map" data-sitemap> <ul> <li data-sitemap-section> <h2><a href="/docs/elements/">API</a> <small>386 pages</small></h2> <ul> <li><a href="/docs/tokens/">Tokens</a></li> <li> <details> <summary>Native elements <small>111</small></summary> <ul data-sitemap-leaves> <li><a href="/docs/elements/native/a/">a</a></li> </ul> </details> </li> </ul> </li> </ul></nav>
This site's own sitemap is built this way, generated from the pages at build time.
JSON Data Loading
When src is set, the component fetches sitemap data from the specified URL and renders the tree dynamically, then adds the expand/collapse-all controls for it. Static markup serves as a fallback. In nav-enhance mode the JSON is { "children": [{ "title", "href", "children" }] }.
1234
<site-map src="/api/sitemap.json" current="/docs/quick-start/"></site-map>
IA tree mode
mode="ia-tree" turns a nested <nav><ul><li><a> list into a tree for information-architecture work: each <li> can carry a page type, a template name and a status, shown as badges and a status dot. A header shows the page count, depth and an expand/collapse-all button.
12345678910111213
<site-map mode="ia-tree" title="Taskflow IA"> <nav> <ul> <li data-page-type="layout" data-template="app-shell" data-status="live"> <a href="/">Home</a> <ul> <li data-page-type="dashboard" data-status="ready"><a href="/dashboard">Dashboard</a></li> <li data-page-type="page" data-status="draft"><a href="/about">About</a></li> </ul> </li> </ul> </nav></site-map>
Attribute on <li> | Values |
data-page-type | layout, section, dashboard, page (default), modal, redirect |
data-template | Any template or view name, shown as an outlined badge |
data-status | draft, ready, live, deprecated — a coloured dot plus visually hidden text |
Keyboard
The tree is a single Tab stop (roving tabindex, starting at the current page’s node or the first node); the links inside nodes leave the Tab order.
| Key | Action |
| ↓ / ↑ | Next / previous visible node |
| → | Expand, or move to the first child (mirrored in right-to-left pages) |
| ← | Collapse, or move to the parent (mirrored in right-to-left pages) |
| Enter | Follow the node’s link |
| Space | Expand/collapse a parent; follow the link on a leaf |
| Home / End | First / last visible node |
Visual (org chart) view
Add data-view="visual" for an SVG org chart with a group of controls for zoom, orientation and detail level. Each control is its own Tab stop. Re-renders swap only the chart, so a control keeps focus while you adjust it. Colours come from theme tokens (light, dark and forced colours).
12345
<site-map mode="ia-tree" title="Taskflow" data-view="visual" data-detail="3"> <nav> <ul>…</ul> </nav></site-map>
The chart is a role="tree" SVG; each node is a treeitem with level, position and expanded state, and the active node is tracked with aria-activedescendant. Focus the chart, then: ↓ first child, ↑ parent, ← → previous and next sibling, Enter follows the node’s link (or collapses or expands a node that has no link), Space collapses or expands, Home/End first/last. The arrow keys follow the drawing. With data-orientation="horizontal" the root is on the left, children sit to the right of their parent and siblings run top to bottom: → first child, ← parent, ↑ ↓ previous and next sibling. The chart is not mirrored in right-to-left pages, so unlike the outline view its arrow keys are not reversed there. Enter sends site-map:select first; call preventDefault() on it to handle the node yourself and stop the navigation.
Data API
| Member | Description |
pages | Get the tree as [{ label, href, pageType, template, status, children }], or assign one to rebuild it (fires site-map:pages-changed) |
src | JSON { "title", "pages": [...] } in the same shape |
site-map:ready | { nodeCount, depth } after the tree is built |
site-map:select | { href, pageType, template } when a node is clicked, or when Enter is pressed on a linked node in the visual view (cancelable there) |
site-map:pages-changed | { pages, source: 'property' } after assigning pages |
Behavior
- Auto-expand: The section containing the current page is automatically expanded on load.
- Expand/collapse all: Control buttons are injected to expand or collapse all
<details> sections at once.
- Current page marking: The link matching the current pathname receives
aria-current="page" and visual styling.
- Progressive enhancement: Without JavaScript, the sitemap renders as a navigable nested list. Sections default to collapsed via
<details>.
Accessibility
- Uses
<nav aria-label="Full site map"> for landmark navigation
- Current page link is marked with
aria-current="page"
- nav-enhance: expand/collapse-all buttons are labelled by their text;
<details>/<summary> provide native disclosure semantics; tab through links, Enter/Space toggles sections
- ia-tree: the
<nav> stays a navigation landmark and its root list becomes the role="tree", with treeitem/group inside, aria-expanded on parents, one Tab stop with arrow-key navigation (mirrored in RTL), Enter follows links, and status announced as text rather than colour alone
- Forced-colors mode keeps badges, status dots and the visual chart visible with system colours
- Without JavaScript, all content is accessible via native HTML disclosure widgets