Is there a difference between these two CSS properties:
background: none;
background: transparent;
- Are they both valid?
- Which one should be used and why?
Is there a difference between these two CSS properties:
background: none;
background: transparent;
As aditional information on @Quentin answer, and as he rightly says,
background
CSS property itself, is a shorthand for:That's mean, you can group all styles in one, like:
This would be (in this example):
So... when you set:
background:none;
you are saying that all the background properties are set to none...You are saying that
background-image: none;
and all the others to theinitial
state (as they are not being declared).So,
background:none;
is:Now, when you define only the color (in your case
transparent
) then you are basically saying:I repeat, as @Quentin rightly says the
default
transparent
andnone
values in this case are the same, so in your example and for your original question, No, there's no difference between them.But!.. if you say
background:none
Vsbackground:red
then yes... there's a big diference, as I say, the first would set all properties tonone/default
and the second one, will only change thecolor
and remains the rest in hisdefault
state.So in brief:
Short answer: No, there's no difference at all (in your example and orginal question)
Long answer: Yes, there's a big difference, but depends directly on the properties granted to attribute.
Upd1: Initial value (aka
default
)Initial value the concatenation of the initial values of its longhand properties:
See more
background
descriptions hereUpd2: Clarify better the
background:none;
specification.To complement the other answers: if you want to reset all background properties to their initial value (which includes
background-color: transparent
andbackground-image: none
) without explicitly specifying any value such astransparent
ornone
, you can do so by writing:There is no difference between them.
If you don't specify a value for any of the half-dozen properties that
background
is a shorthand for, then it is set to its default value.none
andtransparent
are the defaults.One explicitly sets the
background-image
tonone
and implicitly sets thebackground-color
totransparent
. The other is the other way around.