Component Library

← Back to gallery

Progressive step accordion in HTML, CSS and vanilla JS

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

Category: Layout · Tags: accordion, steps, progressive, wizard, disclosure

Live preview

Source (copy-ready)

<section class="dcl-progressive-step-accordion" data-dcl-scheme="light" aria-labelledby="dcl-progressive-step-accordion-title">

<header class="dcl-progressive-step-accordion__header">
  <h2 id="dcl-progressive-step-accordion-title">Progressive step accordion</h2>
  <p class="dcl-progressive-step-accordion__muted">Move through the setup in order, or open a step directly to review it.</p>
  <p class="dcl-progressive-step-accordion__muted" role="status" aria-live="polite" data-step-status>Step 1 of 3</p>
</header>
<details data-step open>
  <summary><span class="dcl-progressive-step-accordion__number">1</span> Choose the workspace</summary>
  <div class="dcl-progressive-step-accordion__panel"><p>Select the workspace that owns the migration. Billing and access stay with that workspace.</p><div class="dcl-progressive-step-accordion__actions"><button type="button" class="dcl-progressive-step-accordion__button-primary" data-next>Continue</button></div></div>
</details>
<details data-step>
  <summary><span class="dcl-progressive-step-accordion__number">2</span> Confirm the data window</summary>
  <div class="dcl-progressive-step-accordion__panel"><p>Choose the freeze time and tell editors when last-minute changes stop being included.</p><div class="dcl-progressive-step-accordion__actions"><button type="button" data-back>Back</button><button type="button" class="dcl-progressive-step-accordion__button-primary" data-next>Continue</button></div></div>
</details>
<details data-step>
  <summary><span class="dcl-progressive-step-accordion__number">3</span> Review the handoff</summary>
  <div class="dcl-progressive-step-accordion__panel"><p>Check the owner, rollback contact and validation count before approving the run.</p><div class="dcl-progressive-step-accordion__actions"><button type="button" data-back>Back</button><button type="button" class="dcl-progressive-step-accordion__button-primary" data-finish>Finish review</button></div></div>
</details>

<script>
(() => {
  const root = document.currentScript.closest(".dcl-progressive-step-accordion");
  if (!root || root.dataset.dclBound === "true") { return; }
  root.dataset.dclBound = "true";
  const instance = Array.from(document.getElementsByClassName("dcl-progressive-step-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();

  const steps = Array.from(root.querySelectorAll("[data-step]"));
  const status = root.querySelector("[data-step-status]");
  let current = 0;
  function announce() {
    if (status) status.textContent = "Step " + (current + 1) + " of " + steps.length;
  }
  function show(index) {
    current = Math.max(0, Math.min(index, steps.length - 1));
    steps.forEach((step, position) => { step.open = position === current; });
    announce();
    const summary = steps[current] && steps[current].querySelector("summary");
    if (summary) summary.focus();
  }
  steps.forEach((step, index) => {
    const summary = step.querySelector("summary");
    if (summary) summary.addEventListener("click", () => {
      if (!step.open) steps.forEach((other) => { if (other !== step) other.open = false; });
      current = index;
      announce();
    });
    const next = step.querySelector("[data-next]");
    const back = step.querySelector("[data-back]");
    const finish = step.querySelector("[data-finish]");
    if (next) next.addEventListener("click", () => show(index + 1));
    if (back) back.addEventListener("click", () => show(index - 1));
    if (finish) finish.addEventListener("click", () => { if (status) status.textContent = "Setup review complete"; });
  });
  announce();

})();
</script>
</section>
<style>
.dcl-progressive-step-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-progressive-step-accordion * { box-sizing: border-box; }
.dcl-progressive-step-accordion h2, .dcl-progressive-step-accordion h3, .dcl-progressive-step-accordion p { margin-block: 0 0.75rem; }
.dcl-progressive-step-accordion button, .dcl-progressive-step-accordion input, .dcl-progressive-step-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-progressive-step-accordion button, .dcl-progressive-step-accordion summary { cursor: pointer; transition: background-color 140ms ease-out; }
.dcl-progressive-step-accordion button:hover, .dcl-progressive-step-accordion summary:hover { color: #ffffff; background-color: #00535a; }
.dcl-progressive-step-accordion button:focus-visible, .dcl-progressive-step-accordion input:focus-visible, .dcl-progressive-step-accordion summary:focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-progressive-step-accordion details { color: #11292f; background-color: #ffffff; border: 1px solid #697f84; border-radius: 0.5rem; margin-block-start: 0.75rem; }
.dcl-progressive-step-accordion summary { font-weight: 650; }
.dcl-progressive-step-accordion input { display: block; inline-size: 100%; color: #11292f; background-color: #ffffff; }
.dcl-progressive-step-accordion [hidden] { display: none !important; }
.dcl-progressive-step-accordion .dcl-progressive-step-accordion__muted { color: #405a60; }
.dcl-progressive-step-accordion .dcl-progressive-step-accordion__panel { color: #405a60; background-color: #ffffff; }
.dcl-progressive-step-accordion .dcl-progressive-step-accordion__well { color: #11292f; background-color: #e4edef; }
.dcl-progressive-step-accordion .dcl-progressive-step-accordion__button-primary { color: #ffffff; background-color: #00535a; }

.dcl-progressive-step-accordion__number { display: inline-block; inline-size: 1.75rem; block-size: 1.75rem; margin-inline-end: 0.5rem; border-radius: 50%; text-align: center; color: #ffffff; background-color: #00535a; }
.dcl-progressive-step-accordion details .dcl-progressive-step-accordion__panel { padding: 0 1rem 0.75rem; }
.dcl-progressive-step-accordion__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-block-start: 0.75rem; }

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

.dcl-progressive-step-accordion[data-dcl-scheme="dark"] .dcl-progressive-step-accordion__number { color: #11292f; background-color: #8fe1da; }

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

When to use

Use for a short linear setup where each step is optional to inspect but most people should complete in order. Keep it to three or four steps and make the visible step count part of the copy. For a real form, validate each step before moving forward.

Avoid

Do not use this pattern for a long form or for sections that have no order; a multi-page form or independent accordion will be easier to correct and review.

Accessibility

Every step remains a native details/summary control, while Back and Continue are real buttons that move focus to the newly opened summary. The current position is exposed as text in a polite status region. Light body text is #405a60 on #ffffff (7.37:1), headings #11292f on #ffffff (15.19:1), and primary-button text #ffffff on #00535a (8.81:1); dark equivalents are #b0c9ce on #142f36 (8.12:1), #eff8f9 on #142f36 (13.07:1), and #11292f on #8fe1da (10.09:1).

Was this useful? Send feedback.