Free HTML tutorial

HTML Classes

The HTML class attribute labels one or more elements so CSS or JavaScript can find them. A class name can be reused on multiple elements.

Add a class to HTML

<h2 class="section-title">Getting started</h2>
<p class="section-title">A short introduction.</p>

Select the class in CSS

Begin a class selector with a period. This rule applies to every element whose class list contains section-title.

.section-title {
  color: #203044;
  margin-bottom: 1rem;
}

An element can have more than one class. Separate class names with spaces, for example class="card featured".

Class names are case-sensitive in selectors. Use names that describe the role of an element rather than its current appearance.