HTML Class Attribute

Class is one of the attributes of the element. The class attribute is used to name a group of elements. So we can apply the same style to all of them. Or javascript functions can call and manipulate them all together.



Class is one of the attributes of the element. The class attribute is used to name a group of elements. So we can apply the same style to all of them. Or javascript functions can call and manipulate them all together.

<tag class="classname">Element Content</tag>
View in Code Editor

The difference between the class and the id addribute is that the id is unique for each element, but the class can be assigned to other elements. Also, each element can have several classes. This means that each element can belong simultaneously to several groups.

<tag class="classname1 classname2">Element Content</tag>
View in Code Editor

To assign more than one class to an element, you need to separate them by spacing.

<< : HTML ID Attribute