W3.JS Add Classes to HTML

Learn XML DOM  Learn JSON  Learn W3.JS  Web Templates  Web Development  Learn XML DOM  W3.JS Reference  HTML Exercises  CSS Exercises  JavaScript Exercises 

Add a class:

Add multiple classes:

Add the "marked" class to an element with id="London":

Try It Yourself » With CSS »

Add the "marked" class to all <h2> elements:

Try It Yourself » With CSS »

Add the "marked" class to an elements with class="London":

Try It Yourself » With CSS »

To add multiple classes to an element, separate each class with a space.

Add both "class1" and "class2" to an element with id="London":

Try It Yourself » With CSS »

Remove a class:

Remove multiple classes:

Remove the "marked" class from an element with id="London":

Try It Yourself » With CSS »

Remove the "marked" class from all <h2> elements:

Try It Yourself » With CSS »

Remove the "marked" class from all elements with class="city":

Try It Yourself » With CSS »

To remove multiple classes from an element, separate each class with a space.

Remove both "class1" and "class2" from an element with id="London":

Try It Yourself » With CSS »

Toggle a class (on/off):

Toggle between two classes:

Toggle between the "marked" class of an element with id="London":

Try It Yourself » With CSS »

Toggle between the "marked" class of all <h2> elements:

Try It Yourself » With CSS »

Toggle between the "marked" class of all elements with class="city":

Try It Yourself » With CSS »

In the examples above, we toggle between one property value (turn on and off a red background color). To toggle between multiple values, add a third parameter. The following example will toggle between a red and blue background color:

Toggle between the class name "class1" and "class2" of id="London:

Try It Yourself » With CSS »

HTML
CSS
JavaScript
SQL
Python
PHP
jQuery
Bootstrap
XML

Your message has been sent to W3Schools.

colorpicker

W3Schools.com