Favorites

DOM DOMTokenList Interface

☕
Enjoying this site?

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

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

A DOMTokenList is a set of space-separated tokens, most often an element's classList, with methods to add, remove, toggle and check them.

Description

The DOMTokenList interface represents a set of space-separated tokens, such as the class names returned by element.classList, or the values of rel on links and sandbox on iframes. It's live, and changes are written back to the attribute.

Its methods are add(), remove(), toggle(), contains(), replace(), item() and supports(), and it has length, value and forEach().

The supports() method is only meaningful for attributes with a fixed set of allowed values, such as rel on links, where it tells you whether the browser understands a value like 'preload'. Tokens can't contain white space; passing a string with a space to add() or toggle() throws an InvalidCharacterError.

Methods

NameDescription
DOMTokenList.add()The add() method of a DOMTokenList, usually element.classList.add(), adds one or more classes.
DOMTokenList.contains()The contains() method of a DOMTokenList, usually element.classList.contains(), checks whether an element has a class.
DOMTokenList.remove()The remove() method of a DOMTokenList, usually element.classList.remove(), removes one or more classes.
DOMTokenList.toggle()The toggle() method of a DOMTokenList, usually element.classList.toggle(), adds a class if it's missing and removes it if it's present.

Example

<div id="card" class="card small">Card</div>
const el = document.getElementById('card');
const cls = el.classList;
console.log(cls.length, cls.value);
cls.add('active');
cls.replace('small', 'large');
cls.forEach(c => console.log(c));

Browser Support

The following information will show you the current browser support for the DOMTokenList 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