About this AccessLint rule
Elements with role="treeitem" must have an accessible name. A treeitem without an accessible name is announced by screen readers as an unnamed or empty item, which makes tree structures unusable for people who rely on assistive technology. Users cannot determine what each item represents, navigate between items meaningfully, or understand the hierarchical relationships within the tree.
Tree widgets are used for nested, hierarchical content like file browsers, navigation menus, or category lists. Each treeitem is a single selectable node in that hierarchy. When a screen reader encounters a treeitem, it announces the item's accessible name along with its position (e.g., "item 3 of 5") and depth in the tree. Without a name, that announcement becomes meaningless.
This rule maps to WCAG 2.1 Success Criterion 4.1.2 (Name, Role, Value), which requires that all user interface components have a name that can be programmatically determined. Because this is a Level A criterion, it is a baseline requirement for accessibility conformance.
How to fix it
There are several ways to give a treeitem an accessible name:
- Text content. Place text directly inside the treeitem element. This is the simplest and most common approach.
aria-label. Add anaria-labelattribute with a descriptive string. This is useful when the visible content of the treeitem is not sufficient on its own (for example, if it contains only an icon).aria-labelledby. Point to another element'sidthat contains the label text. This is useful when the label text already exists elsewhere in the DOM.
The fix depends on context. If the treeitem already contains visible text that describes it, no extra attributes are needed. If it contains only non-text content like icons or images, use aria-label or aria-labelledby to supply the name.
Examples
Treeitems with no accessible name
In this example, the treeitems have no text content and no labeling attributes, so screen readers cannot announce them.
<ul role="tree">
<li role="treeitem">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
</li>
<li role="treeitem">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
</li>
</ul>
Each treeitem contains only a decorative SVG with aria-hidden="true", which means the accessible name is empty.
Fixed with text content
The simplest fix is to add visible text inside each treeitem.
<ul role="tree">
<li role="treeitem">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
Documents
</li>
<li role="treeitem">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
Photos
</li>
</ul>
Fixed with aria-label
When visible text is not desirable in the design, aria-label provides the name directly.
<ul role="tree">
<li role="treeitem" aria-label="Documents">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
</li>
<li role="treeitem" aria-label="Photos">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
</li>
</ul>
Fixed with aria-labelledby
If the label text exists in another element, reference it by id.
<ul role="tree">
<li role="treeitem" aria-labelledby="label-docs">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
<span id="label-docs">Documents</span>
</li>
<li role="treeitem" aria-labelledby="label-photos">
<svg aria-hidden="true"><use href="#folder-icon" /></svg>
<span id="label-photos">Photos</span>
</li>
</ul>
Nested tree with named treeitems
A more complete example showing a nested tree structure where every treeitem has an accessible name through text content.
<ul role="tree" aria-label="File browser">
<li role="treeitem" aria-expanded="true">
Documents
<ul role="group">
<li role="treeitem">Resume.pdf</li>
<li role="treeitem">Cover Letter.docx</li>
</ul>
</li>
<li role="treeitem" aria-expanded="false">
Photos
<ul role="group">
<li role="treeitem">Vacation.jpg</li>
</ul>
</li>
</ul>
Each treeitem here has text content that serves as its accessible name. The role="group" on nested lists communicates the hierarchy, and aria-expanded indicates whether a parent node is open or closed. The tree itself also has an accessible name via aria-label so users understand what the tree widget contains.
Detect accessibility issues automatically
Rocket Validator scans your site with complementary accessibility engines, helping teams find issues across every page.
Help us improve our guides
Was this guide helpful?
๐
Trusted by teams worldwide
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
Scheduled Reports
API Access
Open Source Standards
$7
/ 7 days
Pro Trial
Full Pro access. Cancel anytime.
Start Pro Trial โ
Join teams across 40+ countries