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

Omer Asadullah
Omer Asadullah
10,415 Points

background: or background-color:.... Which is the correct way?

In CSS Deep Dive videos Guil sometimes types background: and sometimes background-color: to set the color of background of an element. My question is which is the correct and appropriate way? Or are both valid?

4 Answers

background-color is used to define color only where as background is a short hand property to define various background properties in a single line which includes color also. Hope this helps.

Omer Asadullah
Omer Asadullah
10,415 Points

Ok. Thanks for your reply.

That he use them both will mean it doesn't matter what you use

That he use them both will mean it doesn't matter what you use

Mugdha is right. This becomes important when you are writing larger css files. Sometimes you will have issues overwriting background: and background-color: based on inheritance. I would always use background if you have an image that needs a fallback color, but not if you only need a color.