0

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;
SaturnsEye
  • 6,297
  • 10
  • 46
  • 62
  • Its both compatible but if you only want to apply color to your background I personally would use "background-color". – Charles Ingalls Jun 19 '14 at 08:56
  • background-color is more preferable – SkyWalker Jun 19 '14 at 08:56
  • 1
    There is in fact a difference if you have something like: background: url(bg.png) repeat-y #FFFFFF; The difference is that the repeat-x direction would be filled up with white. You can also achieve this by using background-image, background-repeat, background-color etc... Background is simply a way of combining all background properties. – JohannesB Jun 19 '14 at 08:58

4 Answers4

1

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.

dabadaba
  • 9,064
  • 21
  • 85
  • 155
1

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:

W3C Schools - Background Property

explorer
  • 127
  • 2
  • 3
  • 13
1

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!!

Pirlo220
  • 11
  • 3
0

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.