Add class to HTML elementJavaScript, Browser · Dec 30, 2020Adds a class to an HTML element. Use Element.classList and DOMTokenList.add() to add the specified class to the element. const addClass = (el, className) => el.classList.add(className); addClass(document.querySelector('p'), 'special'); // The paragraph will now have the 'special' class