HTML class Attribute


The class attribute is used to select any element of the html page. It is a very easy method to select any element using the class attribute. This is why most elements on an HTML page are selected using the class attribute.


First, a class attribute needs to be placed inside an element, and then a value of any name should be given inside that class attribute. The value of this class attribute is used as the selector for that element. A dot should be placed before this velu when this velu is used. This dot indicates that this is a class.


There are two methods of using CSS with this class. First, within the <head> tag, we place the <style> tag, and within the <style> tag, we use it. The second one is, creating a CSS page and styling using classes within it.

HTML class Attribute
HTML class Attribute view

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .my-class{
            text-align: center;
            color: rgb(50, 50, 175);
        }
    </style>
</head>
<body>
<h1 class="my-class">myschoolhouse.in</h1>
</body>
</html>