HTML: Class Attribute

By Xah Lee. Date: .

Purpose of the class attribute

The class attribute is used as a label for an element, so that CSS and JavaScript can get all elements that have the same label. (for the purpose of styling them or do something with them)

Syntax of Class Attribute

The class attribute can have more than one value, separated by space, like this:

<p class="a b c">Alice In Wonderland</p>

order does not matter.

🛑 WARNING: Each html element can have only one class attribute. It's invalid to have more than one, e.g. class="x" class="y".