The HTML class attribute is used to define equal styles for elements with the same class name.

So, all HTML elements with the same class attribute will have the same format and style.

Here we have three <div> elements that point to the same class name:

<!DOCTYPE html>
<html>
<head>
<style>
.cities {
    background-color: black;
    color: white;
    margin: 20px;
    padding: 20px;
} 
</style>
</head>
<body>

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

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

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

</body>
</html>

 

Leave a Reply

Your email address will not be published. Required fields are marked *