Purpose
A tree view displays hierarchical data with expandable and collapsible branches. Common uses include file explorers, organizational charts, and nested navigation structures.
Usage Guidance
- Use tree views for hierarchical data with 3 or more levels of nesting
- For simple nested lists, consider
<ul>with<details>elements instead - Ensure tree item labels are descriptive and unique
Keyboard Support
| Key | Action |
|---|---|
Arrow Right |
Expand collapsed node; move to first child of expanded node |
Arrow Left |
Collapse expanded node; move to parent of collapsed node |
Arrow Down |
Move to next visible node |
Arrow Up |
Move to previous visible node |
Home |
Move to first node |
End |
Move to last visible node |
Enter / Space |
Activate node (expand/collapse or trigger action) |
Screen Reader Behavior
Screen readers announce item level, position, and whether the item is expanded or collapsed. Items without children are announced as βend nodeβ or without expansion state.
ARIA Requirements
role="tree"on the root containerrole="treeitem"on each itemrole="group"on nested<ul>elementsaria-expanded="true|false"on items that have childrentabindex="0"on the focused item;tabindex="-1"on all others (roving tabindex)
Common Mistakes
- Not implementing roving tabindex (all items focusable at once)
- Forgetting
aria-expandedon parent nodes - Missing
role="group"on nested list containers - Not announcing the tree level to screen readers
Live Example
-
- π Accessibility Policy v2.3
- π Training Records 2024
- π Monitoring Reports
-
- π Q1 2024 Audit Report
- π Q3 2024 Audit Report
- π Accessibility Statement
Code Structure
<ul role="tree" aria-label="Document tree">
<li role="treeitem" aria-expanded="false">
<button aria-expanded="false">Folder Name</button>
<ul role="group" hidden>
<li role="treeitem">
<span>Document 1</span>
</li>
<li role="treeitem" aria-expanded="false">
<button aria-expanded="false">Subfolder</button>
<ul role="group" hidden>
<li role="treeitem"><span>Nested Item</span></li>
</ul>
</li>
</ul>
</li>
</ul>