--- id: bad87fee1348bd9aecf08806 title: Use a CSS Class to Style an Element challengeType: 0 videoUrl: 'https://scrimba.com/c/c2MvDtV' --- ## Description
Classes are reusable styles that can be added to HTML elements. Here's an example CSS class declaration: ```html ``` You can see that we've created a CSS class called blue-text within the <style> tag. You can apply a class to an HTML element like this: <h2 class="blue-text">CatPhotoApp</h2> Note that in your CSS style element, class names start with a period. In your HTML elements' class attribute, the class name does not include the period.
## Instructions
Inside your style element, change the h2 selector to .red-text and update the color's value from blue to red. Give your h2 element the class attribute with a value of 'red-text'.
## Tests
```yml tests: - text: Your h2 element should be red. testString: assert($("h2").css("color") === "rgb(255, 0, 0)", 'Your h2 element should be red.'); - text: Your h2 element should have the class red-text. testString: assert($("h2").hasClass("red-text"), 'Your h2 element should have the class red-text.'); - text: Your stylesheet should declare a red-text class and have its color set to red. testString: assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g), 'Your stylesheet should declare a red-text class and have its color set to red.'); - text: Do not use inline style declarations like style="color: red" in your h2 element. testString: assert($("h2").attr("style") === undefined, 'Do not use inline style declarations like style="color: red" in your h2 element.'); ```
## Challenge Seed
```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

  • cat nip
  • laser pointers
  • lasagna

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


```
## Solution
```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

  • cat nip
  • laser pointers
  • lasagna

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


```