Style Change Question


Is there a benefit to using a class to change the text color verses the following:

h2 {color: red;}


Thank you

Using a class is nice because then it’s easy add the same class in several places. And easy to change. What if your boss comes to you and says, Yeah, you know, I love that you hand coded in a red color on all 114 of those buttons. But now I’m thinking I want more of a maroon. Let me know when you’re done, there’re a couple more colors I want to try. If you define those as a class in your css, it will take seconds to change.

DIdn’t think about it like that. Thanks for you insight.

Sorry, seeing your question more clearly now.

Yeah, you could code it directly to h2, but what if your boss also wants the same thing for h4? What if he later decides he only wants it on some h2s.

If you are absolutely, 100% sure you will never need to change it, then changing the style of the element is fine. I’m just never 100% of anything.

You can qualify your h2 css.

#thissection h2 {
   color: red;

#othersection h2 {
   color: blue;

So depending on the h2’s parent, it will take on a different property.