Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Basics (2014) Fundamental Concepts Inheritance

leonteare
leonteare
2,432 Points

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.

leonteare
leonteare
2,432 Points

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
221,293 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.

leonteare
leonteare
2,432 Points

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
221,293 Points

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