How to add a class in h2 elements in HTML to change color?

<style>
  h2 {
    .red-text{
      color:red;
    }
   }
</style>

<h2>CatPhotoApp</h2>

<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>

You can’t nest selectors in CSS. It’s just

<style>
  .red-text {
    color: red;
  }
</style>

However, this alone won’t change the <h2>'s color to red. You’ll need to give it the class attribute with a value of red-text.

<h2 class="red-text">
1 Like