HTML Classes
The class attribute assigns one or more class names to elements, enabling targeted CSS styling and JavaScript selection. Classes are reusable.
Using Classes
The class attribute assigns CSS class names to HTML elements. Multiple elements can have the same class, and a single element can have multiple classes separated by spaces.
Classes are the primary way to apply CSS styles to groups of elements and are commonly used for JavaScript element selection.
<!-- Single class -->
<p class="intro">Introduction paragraph.</p>
<!-- Multiple classes -->
<button class="btn btn-primary btn-large">Click</button>
<!-- Same class on multiple elements -->
<div class="card">Card 1</div>
<div class="card">Card 2</div>