References

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

The HTML aria-setsize attribute

ARIA Accessibility All modern browsers
In short

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

  • In a role="feed", aria-setsize can go on each <article>. It may hold the real total when the supply of articles is fixed, or -1 when that total is very large, open-ended or changes often.
  • Every member of one set carries the same total. In a tree, each group of sibling treeitems is a set of its own, so a branch's children report their own count rather than the size of the whole tree.
  • Rewrite the value on every loaded item when the total changes, such as after a filter narrows the list. The number must equal the count of items in the whole set.
  • In a menu, count the menuitem, menuitemcheckbox and menuitemradio elements and leave separators out of the total.
  • Native <option> elements in a <select> and radio buttons that share a name need no aria-setsize, since the browser already counts them as it counts list items.

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.