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

Accessibility Icon overlaid on a pile of money.
The Business Case for Accessibility: Why Inclusive Design is a Smart Investment

When businesses think about accessibility, they often frame it as a compliance issue—something they have to do to avoid legal trouble. While compliance with laws like the Americans with Disabilities Act (ADA), Section 508, and WCAG (Web Content Accessibility Guidelines) is essential, accessibility isn’t just about avoiding lawsuits. It’s about unlocking market potential, enhancing brand […]

Michael Beck - 08/05/2025

Stylized computer screen showing a PDF. A magnifying glass highlights use of the , , and tag
Creating Accessible PDFs: A Guide to Inclusive Documents

PDFs are everywhere—business reports, government forms, educational materials, and even restaurant menus. But while PDFs are convenient for sharing information, they can be a nightmare for accessibility if not properly formatted. For people who use screen readers, magnifiers, or other assistive technologies, a poorly structured PDF can be completely unusable. Ensuring your PDFs are accessible […]

Michael Beck - 05/05/2025

Flat vector illustration of three characters surrounding an oversized mobile device. The device's screen shows the accessibility man icon along with icons for facebook, Twitter, and Instagram.
Accessible Social Media: Tips for Facebook, Twitter, and Instagram

Social media has become a central part of our daily lives. It’s where we connect, share stories, and engage with brands. But for millions of people with disabilities, social media can be frustratingly inaccessible. Imagine trying to read a post that contains an image—but there’s no description. Or watching a video without captions. Or struggling […]

Michael Beck - 01/05/2025

Cartoon shark wearing sunglasses and earbuds using a desktop computer.
Screen Reader Compatibility: Ensuring Your Site Works for All Users

When was the last time you navigated a website without using your eyes? For millions of people who are blind, have low vision, or experience other disabilities, screen readers provide access to digital content by converting text into speech or braille. Ensuring that your website is fully compatible with screen readers isn’t just a nice-to-have—it’s […]

Michael Beck - 01/05/2025

Closeup of a keyboard. The Enter key now says "Navigation"
Keyboard Navigation: Ensuring Usability Without a Mouse

When designing and building digital experiences, one fundamental principle of accessibility often goes overlooked: not everyone uses—or can use—a mouse. For users who rely solely on their keyboard, whether due to physical disabilities, temporary impairments, or personal preference, your website or application must be operable using just a keyboard. But creating robust keyboard navigation isn’t […]

Michael Beck - 30/04/2025