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

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.