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 anaria-expandedstate, initiallyfalse. Add anaria-controlsproperty pointing to the panel's ID. The panel itself gets arole="region", anaria-labelledbypointing back to the button, and thehiddenattribute. Your JavaScript toggles botharia-expandedandhiddenon 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-expandedto signal if the list is open or closed.aria-controlsto 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 getsaria-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.