Favorites

DOM HTMLCollection Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
HTMLCollection
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

An HTMLCollection is a live list of elements, such as element.children or document.forms. It updates automatically when the page changes.

Description

An HTMLCollection is an array-like list of elements (never text nodes) returned by properties such as children, document.forms and document.images, and by getElementsByClassName() and getElementsByTagName(). It is always live: it changes as elements are added or removed, which can cause surprises when you modify the page while looping over it.

It has length, index access, item() and namedItem(), and works with for...of, but has no forEach(). Convert it with Array.from() for array methods or a stable copy.

Because the collection updates automatically, removing elements while looping over it forwards skips every other element; loop backwards, or copy the collection to an array first. Elements can also be looked up by their id or name through namedItem() or bracket notation, as in document.forms.signup.

Example

<ul id="list">
  <li>One</li>
  <li>Two</li>
</ul>
const list = document.getElementById('list');
const kids = list.children;
console.log(kids.length);
list.append(document.createElement('li'));
console.log(kids.length);   // live: updated automatically
console.log(Array.from(kids).map(li => li.tagName));

Browser Support

The following information will show you the current browser support for the HTMLCollection interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee