Background color?

I noticed that sometimes in the curriculum CSS it uses

background-color: red;

and sometimes it uses simply:

background: red;

is there any particular reason why to use one and not the other. Is one better practice? why do both work?

background-color changes only the color, white background: red also sets (while maybe not intended) background-position, background-repeat and background-image

1 Like

Welcome, gazz.

In general, it is up to you which to use. I prefer to use the shorthand methods, if I will be using more than one property from them.

That being said, you can read more about the usage of background here: Mozilla: Background

As with all shorthand properties, any omitted sub-values will be set to their initial value.

If, for any reason, you do not want a particular property to be it’s initial value, then you must not forget to set it when using shorthand methods.

Hope this helps