The class attribute is used to indicate a class name in a stylesheet. It can also be used by JavaScript to access and manage elements.


syntax:

<tag class="name_of_class"></tag>

Example:

<!DOCTYPE html>
<html>
    <head>
        <title>Class</title> 
        <style>
            .class1{
                font-size: 22px;
            }
        </style>
    </head>
    <body>
        <div class="class1">Hello World!</div>
    </body>
</html>


Important:

  • Look this line of code <div class="class1">Hello World!</div>
  • You can define multiple <div class="class1 class2 class3 ..... .........">Hello World!</div>
  • The class attribute can be used on any HTML element.
  • he class name is case sensitive!