What is this best practice to use that's most compatible across multiple browsers:
background:#ffffff;
or
background-color:#ffffff;
or is it best to use both to cover more:
background:#ffffff;
background-color:#ffffff;
What is this best practice to use that's most compatible across multiple browsers:
background:#ffffff;
or
background-color:#ffffff;
or is it best to use both to cover more:
background:#ffffff;
background-color:#ffffff;
There's no difference about compatibility. The only difference is that using background
you could add several properties in the same line, as you probably know, instead of repeating background-color
, backgroud-image
etc in different lines.
To set the color, you can use either of these.
As per W3C Standards, we shall follow the background-color
property. However, if you follow this, you will be only able to add color and not other options like size, image, attachment
etc.
I would suggest you to go for standard format as it is easy for others to clearly read about the properties.
You can learn more about the background property from:
I prefer background-color. My first reason is readability because in a first glance you can know what's the purpose of that style. When you use plain "background" you can define many properties inside it which makes it more complicated to read.
Background: color position/size repeat origin clip attachment image|initial|inherit;
versus background-color: color|transparent|initial|inherit;
And ie is not fully compatible with all background properties:
Note: IE8 and earlier do not support multiple background images on one element.
Good luck!!
It doesn't really matter if you use background
or background-color
since background
is a prefix/shortcut to:
-color
-image
-position
-attachment
-repeat
Its just that using background
can let you add its additional css properties to prevent repetition of declarations. It is one of the basics of CSS. But if you are only going to change the color of the background and nothing else, I recommend you use background-color
.