How can i use a CSS Class to Style an Element h2 to red?

Tell us what’s happening:

Your code so far


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

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>
  
  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
  
  <div>
    <p>Things cats love:</p>
    <ul>
      <li>cat nip</li>
      <li>laser pointers</li>
      <li>lasagna</li>
    </ul>
    <p>Top 3 things cats hate:</p>
    <ol>
      <li>flea treatment</li>
      <li>thunder</li>
      <li>other cats</li>
    </ol>
  </div>
  
  <form action="/submit-cat-photo">
    <label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
    <label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
    <label><input type="checkbox" name="personality" checked> Loving</label>
    <label><input type="checkbox" name="personality"> Lazy</label>
    <label><input type="checkbox" name="personality"> Energetic</label><br>
    <input type="text" placeholder="cat photo URL" required>
    <button type="submit">Submit</button>
  </form>
</main>

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36 OPR/62.0.3331.72 (Edition Campaign 34).

Link to the challenge:
https://learn.freecodecamp.org/responsive-web-design/basic-css/use-a-css-class-to-style-an-element

In this way, but then you need to apply the class to the element (class="classname")

not working out after including
class=“classname”.red-text {
color;red;
}

You have to add the class to the h2 element.

<h2 class="your-class-name"></h2>

The css was fine like it was, instead you need to give a class attribute to the element you want to style

<h2 class= .red-text { color: red; } .red-text { color: red; } h2 { color: red; }

not working out yet.

am sorry to over disturb you but failed to understand your text…the code please

Look my example. Just change your-class-name to red-text and that’s it :slight_smile:

<h2 class= red-text</h2>
just like the above…is not accepting

Nope, it’s differente, my friend. Details are key when programming :wink:

The h2 tag must be cloded properly and the name of the class must be between quotation marks.

<h2 class="your-class-name"></h2>

You need to add the attribute to the existing element

For example when we add a class of blue-text to a p element we would add class="blue-text" to the opening tag, like this: <p class="blue-text">

So in total

<p class="blue-text">Some random text</p>

<h2 class= red-text>CatphotoApp</h2>
not working out even after doing just like yours

<h2 class= red-text></h2>
this thing has become a pin in my flesh…
it’s still insisting.

Dude, just put some quotation marks around red-text

class="red-text"

that’s it!!

You are missing the quotes plus don’t leave a space after class