Skip to Content

Blog > Creating an Accessible Accordion with HTML Description Lists

Creating an Accessible Accordion with HTML Description Lists

Karl Groves. - 17/04/2025

When designing web components, accessibility is paramount to ensure inclusiveness for all users, including those with disabilities. A common interactive element that greatly benefits from an accessible implementation is the accordion—a user interface component that allows users to expand and collapse content sections. In this tutorial, we will dive deep into building an accessible accordion using HTML description lists (<dl>).

Why Use Description Lists for Accordions?

HTML description lists (<dl>) are designed to pair terms and their descriptions, making them a natural fit for structuring an accordion.
Each term (<dt>) can serve as a clickable header, with its paired description (<dd>) acting as the collapsible content.
This semantic approach is not only meaningful for browsers and search engines but also improves accessibility when combined with proper ARIA attributes.


Structuring the Accordion with HTML

The backbone of our accordion is a <dl> element containing multiple <dt> and <dd> pairs:

<dl class="accordion">
  <dt>
    <button aria-expanded="false" aria-controls="section1" id="accordion1">
      Section 1
    </button>
  </dt>
  <dd id="section1" role="region" aria-labelledby="accordion1">
    <p>Content for section 1.</p>
  </dd>
  <dt>
    <button aria-expanded="false" aria-controls="section2" id="accordion2">
      Section 2
    </button>
  </dt>
  <dd id="section2" role="region" aria-labelledby="accordion2">
    <p>Content for section 2.</p>
  </dd>
</dl>

The buttons are linked to their respective content sections using aria-controls and aria-labelledby attributes, providing clear relationships for screen readers.


Adding Styles with CSS

Styling ensures that collapsed sections are hidden and expanded sections are clearly visible:

.accordion {
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0;
  max-width: 400px;
}

.accordion button {
  width: 100%;
  padding: 10px;
  text-align: left;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.accordion dd {
  display: none;
  padding: 10px;
  background-color: #fafafa;
}

.accordion dd[aria-hidden="false"] {
  display: block;
}

Implementing Toggle Behavior with JavaScript

The following JavaScript snippet controls the expand/collapse behavior while maintaining accessibility attributes:

const buttons = document.querySelectorAll('.accordion dt button');

buttons.forEach((button) => {
  button.addEventListener('click', () => {
    const expanded = button.getAttribute('aria-expanded') === 'true';
    button.setAttribute('aria-expanded', !expanded);
    
    const content = document.getElementById(button.getAttribute('aria-controls'));
    content.setAttribute('aria-hidden', expanded ? 'true' : 'false');
  });
});

Enhancing Accessibility Further

To fully support accessibility, consider:

  • Keyboard Navigation: Ensure users can navigate using Tab and activate with Enter/Space.
  • Focus Management: Set appropriate focus states when expanding content.
  • Screen Reader Announcements: Use aria-live for dynamic announcements.

Final Result

The full, working example can be seen at https://codepen.io/afixt/pen/vEBgYWy

See the Pen
Accessible Accordion Based on Description Lists (DL)
by AFixt (@afixt)
on CodePen.

Learn More

For more tips and training on accessible web development, check out LearningAccessibility.com

Related Blog Posts

AFixt Comments on the WCAG 3 Conformance Model

Comments on the current exploratory WCAG 3 conformance proposal and the Working Group’s related Conformance issue record. AFixt appreciates the substantial effort the Accessibility Guidelines Working Group has invested in developing WCAG 3 and, in particular, in reconsidering limitations that have become apparent through more than two-and-a-half decades of experience with WCAG 1 and WCAG […]

Karl Groves - 19/08/2026

Accessible is conformant

A few years ago, I gave a presentation titled So You Want an Accessibility Score? about the problems associated with attempts to quantify accessibility into a single numerical score. The topic was not particularly new then, and it certainly isn’t new now. Organizations want accessibility scores for essentially the same reasons they want scores for […]

Karl Groves - 12/08/2026

SEO is not accessibility, and we have the data to prove it

Among the many ancillary arguments you tend to hear about why you should care about accessibility is the pitch: “Accessibility improves your SEO!” It’s the sweetener accessibility advocates add add when they suspect compliance alone won’t close the deal. And like most such arguments, it contains just enough truth to survive scrutiny – as long […]

Karl Groves - 11/06/2026

Cool new stuff coming in ARIA 1.3

WAI-ARIA 1.3 is shaping up to be useful for rich document editors, annotation systems, complex forms, and interfaces where visible content does not always map cleanly to what assistive technologies need. Please note: ARIA 1.3 is still a draft. The current W3C ARIA Working Group charter lists WAI-ARIA as a Living Recommendation, with ARIA 1.3 […]

Karl Groves - 20/05/2026

Measuring What Matters

How to Turn Accessibility Work Into Evidence-Based Progress Digital accessibility programs often begin with good intentions: an audit, a backlog of issues, a remediation plan, maybe a few training sessions. But sooner or later, leadership asks a harder question: Are we actually getting better? For many organizations, that question is difficult to answer. Accessibility work […]

Karl Groves - 29/04/2026