What the component does
A "course navigator" built on Jhey Tompkins' article navigator pattern, adapted for an online learning management system. It links to every course lesson, smoothly scrolls to anchored lesson headings, reports how much of the current lesson has been read, toggles light and dark mode, and stays pinned to the bottom of the page as a disclosure that collapses on scroll. No JavaScript is required for the core behavior — only bleeding-edge CSS, fully supported by Chrome at the time of writing.
Markup: a fixed native disclosure
The wrapper is a <details> element with fixed positioning that pins it to the bottom of the page. Behind it sits an <article> holding the lesson, with ids on headings so same-page anchors resolve. The navigator itself lives in the ::details-content pseudo-element, toggled by clicking <summary>. That summary carries four things: a label, the current lesson name, the scroll distance, and the dark mode toggle.
Positioning first:
details {
position: fixed;
inset: 24px; /* Use as margin */
place-self: end center; /* y x */
}
<details>
<!-- The toggle (flex →) -->
<summary>
<span><!-- Toggle label --></span>
<span><!-- Current lesson + % read --></span>
<label><!-- Light/dark-mode toggle --></label>
</summary>
<!-- ::details-content -->
<!-- Course navigation -->
<!-- /::details-content -->
</details>
<article>
<h1 id="sectionA">Section A</h1>
<p>...</p>
<h2 id="sectionB">Section B</h2>
<p>...</p>
<h2 id="sectionC">Section C</h2>
<p>...</p>
</article>
CSS-only dark mode
The toggle markup is a hidden checkbox input (hidden via its hidden attribute), an <i> that becomes a faux checkbox icon, and a <span> for the text label, all inside a <label>, which itself sits inside <summary>. The label's contents are wrapped in a <span> so flexbox gap applies between them. A hidden checkbox still toggles when its label is clicked. An explicit aria-label on the label is worth adding, since implicit labels aren't always announced by screen readers.
<details>
<summary>
<!-- ... -->
<label aria-label="Dark mode">
<input type="checkbox" hidden>
<i></i>
<span>Dark mode</span>
</label>
</summary>
<!-- ... -->
</details>
Icons are selected with conditional rule logic rather than Font Awesome's HTML classes. Using Font Awesome's CSS properties, an <i> followed via the next-sibling combinator by a checked checkbox displays a checked icon; followed by an unchecked checkbox, an unchecked icon. The same logic works with any icon system.
/* Copied from Font Awesome’s CSS */
i::before {
font-style: normal;
font-family: "Font Awesome 6 Free";
display: inline-block;
width: 1.25em; /* Prevents content shift when swapping to differently sized icons by making them all have the same width (this is equivalent to Font Awesome’s .fa-fw class) */
}
/* If followed by a checked checkbox... */
input[type=checkbox]:checked + i::before {
content: "\f058";
font-weight: 900;
}
/* If followed by an unchecked checkbox... */
input[type=checkbox]:not(:checked) + i::before {
content: "\f111";
font-weight: 400;
}
Mode is set at the root: if the root :has the checked checkbox, color-scheme: dark applies; if the root does :not(:has) the unchecked checkbox, color-scheme: light applies.
/* If the root has a checked checkbox... */
:root:has(input[type=checkbox]:checked) {
color-scheme: dark;
}
/* If the root does not have a checked checkbox... */
:root:not(:has(input[type=checkbox]:checked)) {
color-scheme: light;
}
Colors are expressed with the light-dark() function, which takes a light-mode value and a dark-mode value and can stand in for any color data type — including inside a conic gradient later. The demo reuses one HSL color with flipped lightness values per mode.
color: light-dark(hsl(var(--hs) 90%), hsl(var(--hs) 10%));
background: light-dark(hsl(var(--hs) 10%), hsl(var(--hs) 90%));
The light-dark() approach is no better or worse than swapping CSS variables; the choice is yours.
Reading progress without JavaScript
The middle of <summary> displays progress two ways: a "progress pie" and a plain-text percentage. Both are driven by a registered custom property, --percentage, formatted as an integer defaulting to 0. That integer format gives CSS the context to interpolate between 0 and 100.
<details>
<summary>
<!-- ... -->
<span>
<span id="progress-pie"></span>
<span>1. LessonA</span>
<span id="progress-percentage"></span>
</span>
<!-- ... -->
</summary>
<!-- ... -->
</details>
@property --percentage {
syntax: "<integer>";
inherits: true;
initial-value: 0;
}
Keyframes animate the variable across its range:
@keyframes updatePercentage {
to {
--percentage: 100;
}
}
Applying that animation on the root with animation-timeline: scroll() makes it a scroll-driven animation — progress is tied to scroll position rather than the document timeline.
:root {
animation: updatePercentage;
animation-timeline: scroll();
counter-reset: percentage var(--percentage);
}
The integer can be printed through the ::before pseudo-element's content using counter(), followed by the percent symbol:
#progress-percentage::before {
content: counter(percentage) "%";
min-width: 40px; display: inline-block; /* Prevents content shift */
}
The pie is a conic-gradient() with two colors stopped at 0% and the scroll percentage. That requires --percentage as a real percentage, obtained by multiplying by 1%: calc(var(--percentage) * 1%).
#progress-pie {
aspect-ratio: 1;
background: conic-gradient(hsl(var(--hs) 50%) calc(var(--percentage) * 1%), light-dark(hsl(var(--hs) 90%), hsl(var(--hs) 10%)) 0%);
border-radius: 50%; /* Make it a circle */
width: 17px; /* Same dimensions as the icons */
}
Building the course table of contents
Nested lists hold the lesson sections. Two resets carry the UX: padding-left: 0 snaps the parent and nested lists to the left edge of the disclosure, and list-style-position: inside keeps the markers from overflowing by snapping them to the side rather than to the text.
<details>
<summary>
<!-- ... -->
</summary>
<ol>
<li class="active">
<a>LessonA</a>
<ol>
<li><a href="#sectionA">SectionA</a></li>
<li><a href="#sectionB">SectionB</a></li>
<li><a href="#sectionC">SectionC</a></li>
</ol>
</li>
<li><a>LessonB</a></li>
<li><a>LessonC</a></li>
</ol>
</details>
ol {
padding-left: 0;
list-style-position: inside;
}
Nested <li> markers get color: transparent — section titles don't need numbering. Nested lists are used for semantics and, specifically, nested numbered lists: other markers, such as bullets, would cause vertical misalignment between lesson titles and section titles.
ol ol li::marker {
color: transparent;
}
List items outside the current lesson are dimmed, emphasizing the relevant items by de-emphasizing the rest.
details {
/* The default color */
color: light-dark(hsl(var(--hs) 90%), hsl(var(--hs) 10%));
}
/* <li>s without .active that’re direct descendants of the parent <ol> */
ol:has(ol) > li:not(.active) {
/* A less intense color */
color: light-dark(hsl(var(--hs) 80%), hsl(var(--hs) 20%));
}
/* Also */
a {
color: inherit;
}
scroll-behavior: smooth on the root makes anchor jumps smooth — and the percentage tracker keeps working across those jumps.
:root {
scroll-behavior: smooth; /* Smooth anchor scrolling */
scroll-padding-top: 20px; /* A scroll offset, basically */
}
Animating the disclosure open and closed
By default <details> snaps open and shut. To transition smoothly, the demo animates ::details-content from height: 0 to height: auto, which relies on opting in at the root with interpolate-size: allow-keywords.
:root {
interpolate-size: allow-keywords;
}
Set overflow-y: clip on details::details-content so content doesn't spill out during the transition:
details::details-content {
overflow-y: clip;
}
An alternative is sliding the content out before fading it in (and the reverse), which demands more precision. Target both details[open] and details:not([open])\u003c/code\u003e for the before and after states — styling details and overriding with details[open] won't reverse the transition. Apply the same transition to both, with different delays so the fade follows opening and precedes closing. List the transitioned properties individually rather than using all, which is neither performant nor lets you set per-property durations and delays. Transition content-visibility with the allow-discrete keyword, since it is a discrete property.
details:not([open])::details-content {
height: 0;
opacity: 0;
padding: 0 42px;
filter: blur(10px);
border-top: 0 solid light-dark(hsl(var(--hs) 30%), hsl(var(--hs) 70%));
transition:
height 300ms 300ms,
padding-top 300ms 300ms,
padding-bottom 300ms 300ms,
content-visibility 300ms 300ms allow-discrete,
filter 300ms 0ms,
opacity 300ms 0ms;
}
details[open]::details-content {
height: auto;
opacity: 1;
padding: 42px;
filter: blur(0);
border-top: 1px solid light-dark(hsl(var(--hs) 30%), hsl(var(--hs) 70%));
transition:
height 300ms 0ms,
padding-top 300ms 0ms,
padding-bottom 300ms 0ms,
content-visibility 300ms 0ms allow-discrete,
filter 300ms 300ms,
opacity 300ms 300ms;
}
Summary label and icons
The summary starts with a label describing its function — "Navigate course" in the demo — with a matching aria-label so screen readers don't announce everything else in the summary.
<details>
<summary aria-label="Navigate course">
<span>
<i></i>
<span>Navigate course</span>
</span>
<!-- ... -->
</summary>
<!-- ... -->
</details>
display: flex separates the three sections with a gap and removes the default summary marker, so you can supply your own.
i::before {
width: 1.25em;
font-style: normal;
display: inline-block;
font-family: "Font Awesome 6 Free";
}
details i::before {
content: "\f0cb"; /* fa-list-ol */
}
details[open] i::before {
content: "\f00d"; /* fa-xmark */
}
/* For older Safari */
summary::-webkit-details-marker {
display: none;
}
If you favor cursor: pointer on interactive elements, set it on the summary and explicitly make the checkbox's label inherit it — it doesn't do so automatically.
summary {
cursor: pointer;
}
label {
cursor: inherit;
}
Two optional scripts
A one-liner that closes the disclosure when the mouse leaves it:
document.querySelector("details").addEventListener("mouseleave", e => e.target.removeAttribute("open"));
Automatic color-scheme detection uses window.matchMedia on prefers-color-scheme: dark and checks matches; if true, the checkbox is checked and CSS handles the rest. Skipping it is unlikely to upset users who prefer to avoid JavaScript.
if (window.matchMedia("prefers-color-scheme: dark").matches) {
document.querySelector("input[type=checkbox]").checked = true;
}
Feature summary
- Scroll-driven animations
interpolate-size: allow-keywordsfor transitioning between0andauto- smooth scrolling by way of
scroll-behavior: smooth - dark mode magic using the
light-dark()function - a progress chart made with a
conic-gradient() - styling the
::details-contentpseudo-element - animating the
<details>element



