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

Mani Saini
Mani Saini
3,101 Points

What is the difference between background and background-color proptery in CSS?

What is the difference between background and background-color property in CSS?

2 Answers

Tobias Helmrich
Tobias Helmrich
31,602 Points

No, you don't have to use the background property. Just think of background as a shorthand property to write all of the above mentioned properties in one property.

If you want to have a background-color for an image you could either write it with two properties:

body {
    background-color: blue;
    background-image: url('image.jpg');
}

or you could use the shorthand property background:

body {
    background: blue url('image.jpg');
}

I hope that makes it more clear.

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Mani,

with the background-color property you can only set the background color of an element. The background property on the other hand is a shorthand property that allows you to set one or more of the following properties: background-clip, background-color, background-image, background-origin, background-position, background-repeat, background-size, background-attachment.

I hope that helps, if you have further questions let me know! :)

Mani Saini
Mani Saini
3,101 Points

So does that mean if i want to change the background color of an image, i will use background property?