Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

aria-expanded — expanded or collapsed state

`aria-expanded` reports whether controlled content is expanded and must match the real interface state.

Version: WAI-ARIA 1.2

Syntax

<button aria-expanded="false" aria-controls="panel">Details</button>

On an expansion button set the strings true or false. Absence means the element does not declare expandability. Do not give every leaf item in a tree a collapsed state.

Put the attribute on the controlling element, not only the revealed panel. The target can be identified by aria-controls. A state change alone shows no content and supplies no clicking, keyboard, or focus behavior.

The example connects a native button to a hidden panel. One function updates visibility and state together, preventing disagreement after activation. The test checks the visible panel and expanded state in the accessibility tree. Another activation uses the same function to collapse it.

Examples

<!doctype html><meta charset="utf-8">
<button id="toggle" aria-expanded="false" aria-controls="panel">Details</button>
<section id="panel" hidden><h2>Course details</h2><p>Three short lessons.</p></section>
<output id="result"></output>
<script>
const button = document.querySelector('#toggle'), panel = document.querySelector('#panel');
button.addEventListener('click', () => {
  const expanded = button.getAttribute('aria-expanded') !== 'true';
  panel.hidden = !expanded;
  button.setAttribute('aria-expanded', String(expanded));
});
button.click();
document.querySelector('#result').textContent = 'expanded=' + button.getAttribute('aria-expanded') + '; visible=' + !panel.hidden;
</script>

Result

expanded=true; visible=true

The result confirms actual panel opening with matching accessibility semantics.

Sources