Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Fundamental Concepts Inheritance

color: initial; vs color:black;

Hello,

In the video https://teamtreehouse.com/library/css-basics/fundamental-concepts/inheritance, Guil is talks about inheritance. He states that you can tell the browser to ignore inheritance with color: initial. In this particular scenario, it sets the color to black, if you want the text to appear black why would you opt for color: initial; over color: black; in this particular scenario?

(likewise, why would you use color: initial; over color: [hex/rgb/color name]; if the desired color is the same?)

I cannot see it being used in this particular scenario (or many at all) as it does not save multiple lines of code, they are both simply one line, which leads me to the question, is it based on preference?.

Thanks, Leon.

No problem Leon. That would be something good to research. I guess if the browser default is green, then the command would be redundant. But if the default color was orange (that would be funny!), then you would have to specify green to get green.

2 Answers

Hi Leon,

Could it have to do with different browsers? Mozilla, Chrome, IE, Opera, etc have different companies running them or are open source.

It could be that each browser has a different default color so initial takes the color back to the browser default which may not necessarily be black in color.

Hello Joe, thanks for the reply!

I understand that they certain browsers' default colors may differ however, in the case that the default is green, my question is, why not just use color: green; instead of color: initial;.

thanks :)

Steven Parker
Steven Parker
231,248 Points

The choice should be based on intention.

If you want the color to be black, you should set it to black explicitly.

You would use "initial" if you wanted to set it to the color it would have if no value were set for any ancestor it might inherit from. Generally, this happens to be black but that's really up to the browser.

Thanks Steven!

Didn't click in my head that even though it would inherit from the browser, that it would show differently on those browsers that do differ. Although nice to know, I doubt I will be using the color: initial; any time soon.

Leon.

Steven Parker
Steven Parker
231,248 Points

For color, you might think of "initial" as being the term for "normal".