Component Library

← Back to gallery

Nested guide accordion in HTML, CSS and vanilla JS

A copy-paste Nested guide accordion in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Layout · Tags: accordion, nested, guide, disclosure, tree

Live preview

Source (copy-ready)

<section class="dcl-nested-guide-accordion" data-dcl-scheme="light" aria-labelledby="dcl-nested-guide-accordion-title">

<header class="dcl-nested-guide-accordion__header">
  <p class="dcl-nested-guide-accordion__eyebrow dcl-nested-guide-accordion__muted">Implementation guide</p>
  <h2 id="dcl-nested-guide-accordion-title">Nested guide accordion</h2>
  <p class="dcl-nested-guide-accordion__muted">Open a phase, then choose only the topic you need inside it.</p>
</header>
<div class="dcl-nested-guide-accordion__tree">
  <details class="dcl-nested-guide-accordion__branch" open>
    <summary class="dcl-nested-guide-accordion__branch-summary"><span>Prepare the workspace</span><span class="dcl-nested-guide-accordion__count">2 topics</span></summary>
    <div class="dcl-nested-guide-accordion__branch-body">
      <p class="dcl-nested-guide-accordion__panel">Set up once before inviting the rest of the team.</p>
      <details class="dcl-nested-guide-accordion__leaf" open><summary>Create the workspace</summary><div class="dcl-nested-guide-accordion__panel"><p>Name the workspace after the team or client it serves, then choose the closest data region.</p></div></details>
      <details class="dcl-nested-guide-accordion__leaf"><summary>Connect source control</summary><div class="dcl-nested-guide-accordion__panel"><p>Connect the repository after confirming who may approve production changes.</p></div></details>
    </div>
  </details>
  <details class="dcl-nested-guide-accordion__branch">
    <summary class="dcl-nested-guide-accordion__branch-summary"><span>Build the first release</span><span class="dcl-nested-guide-accordion__count">3 topics</span></summary>
    <div class="dcl-nested-guide-accordion__branch-body">
      <p class="dcl-nested-guide-accordion__panel">Work through these topics when the first slice is ready to validate.</p>
      <details class="dcl-nested-guide-accordion__leaf"><summary>Seed realistic content</summary><div class="dcl-nested-guide-accordion__panel"><p>Use a small copy of real content rather than placeholder text so wrapping and empty states are visible.</p></div></details>
      <details class="dcl-nested-guide-accordion__leaf"><summary>Review permissions</summary><div class="dcl-nested-guide-accordion__panel"><p>Check each role against the few actions it needs, removing broad access before wider testing.</p></div></details>
      <details class="dcl-nested-guide-accordion__leaf"><summary>Rehearse rollback</summary><div class="dcl-nested-guide-accordion__panel"><p>Record the exact restore point and practice returning to it before the release window.</p></div></details>
    </div>
  </details>
  <details class="dcl-nested-guide-accordion__branch">
    <summary class="dcl-nested-guide-accordion__branch-summary"><span>Operate after launch</span><span class="dcl-nested-guide-accordion__count">2 topics</span></summary>
    <div class="dcl-nested-guide-accordion__branch-body">
      <p class="dcl-nested-guide-accordion__panel">Keep operational answers close to the team that owns the service.</p>
      <details class="dcl-nested-guide-accordion__leaf"><summary>Read the health signals</summary><div class="dcl-nested-guide-accordion__panel"><p>Review failed jobs, queue age and customer-facing errors together before declaring an incident.</p></div></details>
      <details class="dcl-nested-guide-accordion__leaf"><summary>Rotate access</summary><div class="dcl-nested-guide-accordion__panel"><p>Remove departing operators the same day and rotate shared credentials on the agreed schedule.</p></div></details>
    </div>
  </details>
</div>

<script>
(() => {
  const root = document.currentScript.closest(".dcl-nested-guide-accordion");
  if (!root || root.dataset.dclBound === "true") { return; }
  root.dataset.dclBound = "true";
  const instance = Array.from(document.getElementsByClassName("dcl-nested-guide-accordion")).indexOf(root);
  if (instance > 0) {
    const references = ["id", "aria-labelledby", "aria-controls", "aria-describedby", "for", "name"];
    for (const element of [root, ...root.querySelectorAll("*")]) {
      for (const attr of references) {
        if (element.hasAttribute(attr)) element.setAttribute(attr, element.getAttribute(attr) + "--" + instance);
      }
      const href = element.getAttribute("href");
      if (href && href.startsWith("#")) element.setAttribute("href", href + "--" + instance);
    }
  }
  const preference = matchMedia("(prefers-color-scheme: dark)");
  const apply = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
  preference.addEventListener("change", apply);
  apply();

})();
</script>
</section>
<style>
.dcl-nested-guide-accordion { color: #11292f; background-color: #ffffff; color-scheme: light; font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border: 1px solid #697f84; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-nested-guide-accordion * { box-sizing: border-box; }
.dcl-nested-guide-accordion h2, .dcl-nested-guide-accordion h3, .dcl-nested-guide-accordion p { margin-block: 0 0.75rem; }
.dcl-nested-guide-accordion button, .dcl-nested-guide-accordion input, .dcl-nested-guide-accordion summary { min-block-size: 44px; border: 1px solid #697f84; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit; color: #11292f; background-color: #e4edef; }
.dcl-nested-guide-accordion button, .dcl-nested-guide-accordion summary { cursor: pointer; transition: background-color 140ms ease-out; }
.dcl-nested-guide-accordion button:hover, .dcl-nested-guide-accordion summary:hover { color: #ffffff; background-color: #00535a; }
.dcl-nested-guide-accordion button:focus-visible, .dcl-nested-guide-accordion input:focus-visible, .dcl-nested-guide-accordion summary:focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-nested-guide-accordion details { color: #11292f; background-color: #ffffff; border: 1px solid #697f84; border-radius: 0.5rem; margin-block-start: 0.75rem; }
.dcl-nested-guide-accordion summary { font-weight: 650; }
.dcl-nested-guide-accordion input { display: block; inline-size: 100%; color: #11292f; background-color: #ffffff; }
.dcl-nested-guide-accordion [hidden] { display: none !important; }
.dcl-nested-guide-accordion .dcl-nested-guide-accordion__muted { color: #405a60; }
.dcl-nested-guide-accordion .dcl-nested-guide-accordion__panel { color: #405a60; background-color: #ffffff; }
.dcl-nested-guide-accordion .dcl-nested-guide-accordion__well { color: #11292f; background-color: #e4edef; }
.dcl-nested-guide-accordion .dcl-nested-guide-accordion__button-primary { color: #ffffff; background-color: #00535a; }

.dcl-nested-guide-accordion__header { margin-block-end: 1rem; }
.dcl-nested-guide-accordion__eyebrow { font-size: 0.875rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.dcl-nested-guide-accordion__branch { padding: 0; overflow: hidden; }
.dcl-nested-guide-accordion__branch-summary { display: flex; justify-content: space-between; gap: 1rem; border: 0; border-radius: 0; padding: 0.875rem 1rem; }
.dcl-nested-guide-accordion__count { font-weight: 500; white-space: nowrap; }
.dcl-nested-guide-accordion__branch-body { padding: 0 1rem 1rem; }
.dcl-nested-guide-accordion__leaf { margin-inline-start: 1rem; border-inline-start: 0.25rem solid #697f84; border-radius: 0.375rem; }
.dcl-nested-guide-accordion__leaf summary { border-radius: 0.25rem; }
.dcl-nested-guide-accordion__leaf .dcl-nested-guide-accordion__panel, .dcl-nested-guide-accordion__branch-body > .dcl-nested-guide-accordion__panel { padding: 0.75rem 0 0.25rem 1rem; }

.dcl-nested-guide-accordion[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; border-color: #839fa5; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] button, .dcl-nested-guide-accordion[data-dcl-scheme="dark"] input, .dcl-nested-guide-accordion[data-dcl-scheme="dark"] summary { color: #eff8f9; background-color: #1c3c44; border-color: #839fa5; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] button:hover, .dcl-nested-guide-accordion[data-dcl-scheme="dark"] summary:hover { color: #11292f; background-color: #8fe1da; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] button:focus-visible, .dcl-nested-guide-accordion[data-dcl-scheme="dark"] input:focus-visible, .dcl-nested-guide-accordion[data-dcl-scheme="dark"] summary:focus-visible { outline-color: #8fe1da; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] details { color: #eff8f9; background-color: #142f36; border-color: #839fa5; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] input { color: #eff8f9; background-color: #142f36; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] .dcl-nested-guide-accordion__muted { color: #b0c9ce; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] .dcl-nested-guide-accordion__panel { color: #b0c9ce; background-color: #142f36; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] .dcl-nested-guide-accordion__well { color: #eff8f9; background-color: #1c3c44; }
.dcl-nested-guide-accordion[data-dcl-scheme="dark"] .dcl-nested-guide-accordion__button-primary { color: #11292f; background-color: #8fe1da; }

.dcl-nested-guide-accordion[data-dcl-scheme="dark"] .dcl-nested-guide-accordion__leaf { border-inline-start-color: #839fa5; }

@media (prefers-reduced-motion: reduce) { .dcl-nested-guide-accordion * { transition: none !important; } }
</style>

When to use

Use for documentation or onboarding material with a real hierarchy, where a reader first chooses a broad phase and then opens one topic inside it. Keep the number of nested levels to two so the indentation remains understandable. Replace the guide copy with the shortest headings that still name the task.

Avoid

Do not use deep nesting for a flat FAQ or for content readers must compare side by side; flatten the list instead of making them hunt through branches.

Accessibility

Every level is a native details and summary pair, so Tab reaches each topic and Enter or Space toggles it without custom ARIA. Nested summaries keep the same keyboard model, and focus is shown by a 3px outline. Light text is #405a60 on #ffffff (7.37:1) or #11292f on #e4edef (12.78:1); dark text is #b0c9ce on #142f36 (8.12:1) or #eff8f9 on #1c3c44 (10.94:1).

Was this useful? Send feedback.