References

Beginner-friendly references for web development, with live, editable examples.

The HTML aria-setsize attribute

ARIA Accessibility All modern browsers Updated
Quick answer

The aria-setsize attribute states the total number of items in a set — a list, listbox, menu or tree — when the DOM contains only some of them. Pair it with aria-posinset so screen readers can say "item 5 of 200".

Overview

The aria-setsize attribute defines the total number of items in a set when not all are in the DOM.

It describes an element's place in a larger set or hierarchy. This matters when not all items are present in the DOM at once — a virtualized list or a lazy-loaded tree — so assistive technology cannot count them itself. For fully-rendered native lists, the browser computes position and size for you.

Like all ARIA, aria-setsize changes only the accessibility tree — what assistive technology perceives — never the element's behavior or appearance. The first rule of ARIA applies: if a native HTML element or attribute conveys this, use that instead, and only reach for ARIA when nothing native fits.

Syntax

<li role="option" aria-setsize="200" aria-posinset="5"> … </li>

Values

Value
An integer (use -1 if the total is unknown).

Example

Live example
<li role="option" aria-setsize="200" aria-posinset="5">Item</li>

Best practices

  • Follow the first rule of ARIA — use a native HTML element or attribute that conveys this where one exists, rather than adding ARIA.
  • Use these when the full set is not in the DOM (virtualized lists, lazy-loaded trees).
  • Set aria-posinset and aria-setsize together for each item.
  • For fully-rendered native lists, let the browser compute position and size instead.

Frequently asked questions

What does aria-setsize do?
Defines the total number of items in a set when not all are in the DOM.
When do I need aria-posinset and aria-setsize?
When not all items in a set are present in the DOM, so the browser cannot count them — for example a virtualized list.
Do native lists need these attributes?
No. A fully-rendered <ul> or <ol> already conveys each item's position and the total.
Do I need aria-setsize if native HTML already conveys it?
Usually not. ARIA is for what native HTML cannot express; redundant or incorrect ARIA can make accessibility worse. Reach for it only when no native element fits.