Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
HTML & Accessibility (a11y)
  1. 1.HTML Fundamentals: Structure & Core Elements
  2. 2.Lists, Tables & Basic Forms
  3. 3.Semantic HTML5 & Document Outline
  4. 4.Advanced Forms & Input Validation
  5. 5.Multimedia & Embedded Content Accessibility
  6. 6.Introduction to ARIA: Roles & Landmarks
  7. 7.ARIA States & Properties for Dynamic Content
  8. 8.Keyboard Accessibility & Focus Management
  9. 9.Advanced Accessibility Patterns & Custom Controls
  10. 10.Accessibility Testing, WCAG & Interview Prep
HTML & Accessibility (a11y)
07

Web Fundamentals · Lesson 7 of 10 · 4 min

ARIA States & Properties for Dynamic Content

This is how you prove you can build accessible components, not just static pages. Get this wrong, and you signal you're not ready for a senior role.

States vs. Properties: The Core Distinction

ARIA attributes fall into two categories: states and properties. You need to know the difference.

Properties define relationships. They rarely change. Think aria-labelledby or aria-controls. You set them once to wire two elements together.

States describe a current condition. They change constantly with user interaction. aria-expanded, aria-selected, and aria-checked are the ones you'll use most.

In an interview, that's your answer. Properties are the component's wiring diagram; states are the live status lights.

The Most Common Pattern: Toggling Content

The most frequent use of ARIA states is showing and hiding content. Accordions, dropdown menus, and mobile navigation all use the same pattern. The key attributes are aria-expanded (the state) and aria-controls (the property).

aria-expanded tells assistive tech if the controlled content is visible (true) or not (false).

aria-controls points to the id of the content being controlled. This creates a programmatic link between the trigger and the content.

Here is the minimal, correct implementation for a toggle.

<button
  id="toggle-btn"
  aria-expanded="false"
  aria-controls="content-panel"
>
  Toggle Content
</button>

<div id="content-panel" role="region" aria-labelledby="toggle-btn" hidden>
  <p>This content is now visible.</p>
</div>

<script>
  const toggleBtn = document.getElementById('toggle-btn');
  const contentPanel = document.getElementById('content-panel');

  toggleBtn.addEventListener('click', () => {
    const isExpanded = toggleBtn.getAttribute('aria-expanded') === 'true';
    toggleBtn.setAttribute('aria-expanded', String(!isExpanded));
    contentPanel.hidden = isExpanded;
  });
</script>

Notice the hidden attribute. It removes the element from the accessibility tree entirely. Toggling display: none with CSS works too, but hidden is the modern, semantic standard.

The trap: Forgetting to update the state. If you only change visibility with CSS or hidden but don't toggle aria-expanded, a screen reader user will have no idea anything happened. The state must stay in sync with the UI.

Interview question: "How would you make an accessible accordion?"

Start with a <button> for the header. Give it an aria-expanded state, initially false. Add an aria-controls property pointing to the panel's ID. The panel itself gets a role="region", an aria-labelledby pointing back to the button, and the hidden attribute. Your JavaScript toggles both aria-expanded and hidden on click.

This state flow is non-negotiable.

Announcing Changes with aria-live

Sometimes content changes outside the user's current focus. Think of a "message sent" notification, search results updating as you type, or a stock ticker.

Sighted users see this. Screen reader users hear nothing unless you tell the browser to announce it. This is what aria-live is for. You add aria-live to a container element, and when you inject new content into that container, assistive tech will announce it.

There are two main settings:

  • aria-live="polite": Waits for the user to finish what they're doing. This is what you want 99% of the time. Use it for status updates, notifications, and changing search results.
  • aria-live="assertive": Interrupts the user immediately. This is extremely disruptive. Only use it for critical, time-sensitive errors, like "Your session has expired."

The trap: Overusing assertive. It's the accessibility equivalent of a modal dialog you can't close. If you use it for a "Saved successfully" message, you're creating a terrible experience. When in doubt, use polite. The role="status" attribute is a common shortcut for aria-live="polite".

What to Say for "Design a Custom Dropdown"

This is a classic system design-style question for frontend accessibility. It tests if you can combine multiple ARIA concepts. Don't write the code; just list the parts.

First, state the first rule of ARIA: don't do this if a native <select> element will work. It's already accessible. Building a custom one is for when you need custom styling or functionality that <select> can't provide.

The key attributes you'll need are:

  • The button: aria-haspopup="listbox" to signal it opens a list of options. aria-expanded to signal if the list is open or closed. aria-controls to link it to the listbox container.
  • The list container: role="listbox". This is the semantic container for the options.
  • The options: Each item gets role="option". The currently selected one gets aria-selected="true".

This answer shows you understand the relationships between components, not just isolated attributes. It's a senior-level response. The next lesson on focus management is also critical for this component, but this covers the ARIA states and properties.

Try it

Take the toggle button code. Add a second button and panel. Modify the script so that opening one accordion panel automatically closes the other. This is a common requirement and forces you to manage state across multiple elements.

Next: Keyboard Accessibility & Focus Management.

Lock it in — apply this lesson under interview conditions.

Try an AI mock interview
Previous

Introduction to ARIA: Roles & Landmarks

Next

Keyboard Accessibility & Focus Management