What is the difference in efficiency between background-color: #BADA55; and background: #BADA55;? I realize it’s quite trivial, but is there a difference in how the browser extracts the values of each. Also, on a slightly related note, on CSS3Please I noticed that for linear-gradients they specified them using background-image. Is there any reason not to simply use background?
What is the difference in efficiency between background-color: #BADA55; and background: #BADA55; ? I
Share
The spec makes no mention of how browsers should implement parsing of properties, and in particular, shorthand properties. All there is to it is a grammar, and the grammar says nothing about its implementation. How a browser parses a shorthand declaration then, I suspect, is entirely implementation dependent and not easily answered (unless you have the source code, of course).
In fact, the main reason why we have numerous CSS hacks specifically catered to IE is because of how differently (and often poorly) it understands CSS.
The answer lies in your previous sentence:
Indeed; CSS gradients are considered images for use with backgrounds, and are documented in the Image Values module. The individual background property they apply to is
background-image.If you use the shorthand property to specify either only the color or only a gradient, it will use the initial value for the rest of the values. If this difference in used styles matters, then the difference in performance becomes completely out of the question, because it’s no longer a fair comparison.
In this example, the second
backgroundshorthand declaration will completely override the first one, leaving you with a solid color and no gradient as the initial value ofbackground-imageisnone:The purpose of the shorthand notation is to specify values for multiple related properties in a single declaration, so in order for both the gradient and the color to apply, it should be rewritten as: