Under Construction: The content on this site draft material. It is not the official content of this site and should not be followed at this time.

Not Legal Advice: The content on this site is provided for informational purposes only and does not constitute legal advice. Consult a qualified attorney for advice specific to your situation.

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 container
  • role="treeitem" on each item
  • role="group" on nested <ul> elements
  • aria-expanded="true|false" on items that have children
  • tabindex="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-expanded on 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
  • πŸ“„ 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>