Favorites

DOM DOMTokenList.add() Method

☕
Enjoying this site?

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

Buy us a coffee
DOMTokenList.add()
DOM DOMTokenList MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The add() method of a DOMTokenList, usually element.classList.add(), adds one or more classes. Classes already present are ignored.

Description

The add() method adds the given tokens to the list, most commonly adding CSS classes with element.classList.add(). Tokens that are already present aren't duplicated. Tokens can't contain spaces; pass several arguments to add several classes.

Because add() ignores classes that are already present, there's no need to check first with contains(). If the element had no class attribute before, one is created.

Adding a class and letting CSS do the styling keeps presentation in your style sheets, and makes it easy to combine with transitions: adding a class such as is-open can trigger a CSS transition defined on that class.

Syntax

tokenList.add(token1, token2, ...)

Parameters

  • token1, token2, ...One or more tokens (class names) to add.

Return Value

None (undefined).

Example

<style>.rounded{border-radius:8px}.shadow{box-shadow:0 2px 8px #0003}</style>
<div id="box" class="card" style="padding:12px">Box</div>
const box = document.getElementById('box');
box.classList.add('rounded', 'shadow', 'rounded');
console.log(box.className);

Browser Support

The following information will show you the current browser support for the DOMTokenList.add() method. Hover over a browser icon to see the version that first introduced support for this method.

This method 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