HTML class attribute is used to define one or more class names for an element.
The class attribute is defined in the style tag using dot(.) symbol followed by class name.
The class name is case-sensitive.
In a single HTML document, you can use the same class with different elements.
Explanation of the above example:
In this example, we have declared classes with the name “.title” and “.description” respectively in the style tag.
Then these classes are used with the HTML elements. The “.title” class is used with <h2> tag and “.description” is used with <p> tag. The properties defined inside the classes are applied to the particular element on which it is used.
Use of Class Attribute on Inline Elements:
In HTML you can use multiple classes on a single element.
If you use multiple classes on an element then you just have to separate those classes by a space.
In this example, all header elements have the same class, and <h1> and <h3> are also styled with the different class names.
Same class with Different Tag:
You can use the same class with different tags like <h1>, <p> and <div> etc. to get the same style.
When you click the button, color of the all elements with class name “technology” will change.