HTML - The class attribute

> (World Wide) Web - (W3|WWW) > HyperText markup Language (HTML)

1 - About

The class attribute is a global attribute (ie Every HTML element may have a class attribute specified) that permits to (select|categorize) elements.

Assigning classes to an element affects:

Advertising

3 - Value

The value is a set of space-separated tokens representing the various classes that the element belongs to. A token is any string of one or more characters, none of which are space characters.

<div class='firstclass secondclass'/>

Authors are encouraged to use values that describe the nature of the content, rather than values that describe the desired presentation of the content.

4 - Management

4.1 - Add / Delete / Modify (DOM Operations)

To manipulate the class attribute with script, see DOM - Class attribute

4.2 - Join

4.3 - Css: If a class is not present

Example with the logical pseudo-element: if the class fade is present but not the class show, the opacity will be set a 0.

.fade:not(.show) {
    opacity: 0;
}

5 - Documentation / Reference

Advertising