The class attribute in HTML is used to set one or more classnames for an element. With the specified class name you can work it through CSS and point in a stylesheet.
Let us now see an example to implement the class attribute in HTML −
Example
<!DOCTYPE html>
<html>
<head>
<style>
h2.demo {
color: orange;
background-color: black;
}
</style>
</head>
<body>
<h1>Resources</h1>
<h2 class="demo">Text Tutorials</h1>
<h2 class="demo">Video Tutorials</h1>
<h2 class="demo">Interview Questions and Answers</h1>
<h2 class="demo">Online Quiz</h1>
</body>
</html>Output

In the above example, we have set a class name for the element <h2> −
<h2 class="demo">Text Tutorials</h1> <h2 class="demo">Video Tutorials</h1>
This is set with a style to update the text as well as background color of the <h2> element −
h2.demo {
color: orange;
background-color: black;
}