Favorites

DOM Element.classList Property

☕
Enjoying this site?

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

Buy us a coffee
Element.classList
DOM Element PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The classList property gives a live list of an element's CSS classes, with methods to add, remove, toggle and check classes.

Description

The read-only classList property of the Element interface returns a live DOMTokenList of the element's class names. It is the easiest way to change the classes of an element without editing the class attribute string by hand.

Use add() and remove() to change classes (both accept several names), toggle() to switch one on or off, contains() to check for one and replace() to swap one for another. toggle() also takes a second argument to force the class on or off.

Although the property itself is read-only, the list it returns is live: it updates when the class attribute changes, and changes made through it update the attribute. Toggling classes and letting CSS handle the styling is usually better than changing styles directly in JavaScript.

Syntax

element.classList

Value

A live DOMTokenList of the element's classes, with methods such as add(), remove(), toggle() and contains().

Example

<p id="msg" class="note">Message</p>
<style>.note{padding:6px}.warning{background:#fef3c7}</style>
const msg = document.getElementById('msg');

msg.classList.add('warning', 'big');
console.log(msg.className);

msg.classList.remove('big');
console.log(msg.classList.contains('warning'));

msg.classList.toggle('hidden');
console.log(msg.classList);

Browser Support

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

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