In HTML, the “class” attribute is used to specify one or more class names for an HTML element. It is used to apply styling and formatting to specific elements using CSS.
The “class” attribute is included in the opening tag of an HTML element and its value can be any string of characters, with multiple class names separated by spaces. For example:
<div class="container main-content">
<!-- content here -->
</div>
In this example, the “class” attribute is used to assign two class names to the <div> element: “container” and “main-content”. These class names can be used in CSS to apply specific styles to this particular element or group of elements. For example:
This CSS code will apply a maximum width of 1200 pixels and centered margin to any element with the “container” class, and a white background and padding of 20 pixels to any element with the “main-content” class.
