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 How to Make a Website Customizing Colors and Fonts Use Classes in CSS

Stacy Fabian
Stacy Fabian
2,246 Points

When to use "background:" and when to use "background-color:"?

In showing how to change the CSS styling of background colors, sometimes the videos instructs to use "background" and sometimes it instructs to use "background-color", maybe I missed it, but I can't tell how to quickly know when to use which one? If anyone can "dumb it down" or "simplify" it for me, that would be awesome. :)

3 Answers

Kevin Korte
Kevin Korte
28,135 Points

Background is a 'shorthand'. Background-color is very specific. It is expecting a color. Background could be a color, or an image, etc. I usually just use the background shorthand because it's faster to write.

https://developer.mozilla.org/en-US/docs/Web/CSS/background

Michael Hulet
Michael Hulet
47,869 Points

I'm pretty sure they're interchangeable, but I personally just use background in every situation. It makes changing the background with JavaScript easier, and it's also technically shorter than background-color, which theoretically saves file size and thereby network load and transmission time, but the difference there is so small that it's virtually nonexistent. As far as I understand, though, it's really your choice

Stacy Fabian
Stacy Fabian
2,246 Points

Ok, that's what it seemed like to me but I wanted to make sure I wasn't missing something. Thanks!