HTML class Attribute

The HTML class attribute is used to specify the HTML object category.

Many HTML objects can share the same class.


Using The class Attribute

The class attribute is often used to identify a class name on a style sheet. It can also be used by JavaScript to access and manage items in the name of a particular class.

In the following example we have three <div> items with a class attribute with "city" value. All three features of <div> will be sorted equally according to the description of the city style in the title section:

Example
<!DOCTYPE html>
<html>
<head>
<style>
.city {
  background-color: tomato;
  color: white;
  border: 2px solid black;
  margin: 20px;
  padding: 20px;
}
</style>
</head>
<body>

<div class="city">
  <h2>London</h2>
  <p>London is the capital of England.</p>
</div>

<div class="city">
  <h2>Paris</h2>
  <p>Paris is the capital of France.</p>
</div>

<div class="city">
  <h2>Tokyo</h2>
  <p>Tokyo is the capital of Japan.</p>
</div>

</body>
</html>