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

ADA Title II and PDFs: Fix, Archive, or Delete?

Imagine you work for a state government agency. Over the years, your department has diligently published reports, meeting minutes, forms, budget documents, and countless other materials as PDFs. A quick inventory shows thousands of them – some from last week, others dating back more than a decade. At the time they were created, nobody thought […]

Karl Groves - 30/09/2025

A Quick Primer on Accessible Pagination

Pagination is a common feature across many websites, from news archives and product listings to blogs and search results. Despite its simplicity on the surface, pagination is one of those UI patterns that can be surprisingly nuanced when it comes to accessibility. Most developers implement it using visual styling alone, assuming it “just works.” Unfortunately, […]

Karl Groves - 17/09/2025

Why Now Is Not the Time to Think About WCAG 3

If you work in accessibility or are responsible for compliance at your organization, you’ve probably heard about WCAG 3.0. The W3C has been developing it for years, and the most recent Working Draft was released in September 2025. At first glance, it feels like a big leap forward: a standard that promises to address gaps […]

Karl Groves - 17/09/2025

Accessible by Design: Improving Command Line Interfaces for All Users

The command line interface (CLI) remains a foundational tool in software development, system administration, and DevOps workflows. While graphical user interfaces have become more ubiquitous, the CLI endures due to its flexibility, speed, and power. Yet, for many users with disabilities, particularly those who are blind or visually impaired, command line tools can present unnecessary […]

Karl Groves - 16/09/2025

Reviewing the Logic and Value of the W3C’s Accessibility Maturity Model

Recently, the Web Accessibility Initiative posted on LinkedIn asking for feedback on their Accessibility Maturity Model. While we will be submitting answers to the specific questions in their post, we’d like to also comment on a bigger question: Why does this Accessibility Maturity Model even exist, in the first place? There are strong sentiments that […]

Karl Groves - 11/09/2025