Is there any difference between background-clip and background-origin?
From CSS3.info:
The background-origin property is used to determine how the background-position of a background in a certain box is calculated.
The background-clip property is used to determine whether the backgrounds extends into the border or not.
According to the MDN:
The background-clip CSS property specifies whether an element's background, either the color or image, extends underneath its border.
while
The background-origin CSS property determines the background positioning area, that is the position of the origin of an image specified using the background-image CSS property.
- https://developer.mozilla.org/en-US/docs/CSS/background-clip
- https://developer.mozilla.org/en-US/docs/CSS/background-origin
Both properties have three options: border-box
, padding-box
, and content-box
. The background-origin
property determines where the background is placed (defaulting to padding-box) while the background-clip
determines what part of the background is shown (defaulting to border-box). The properties can be used together or independently.
Some examples may be useful:
- Default (neither property specified)
Background-origin
- Background-origin set to
border-box
- Notice how the background image has been shifted slightly up and to the left so that the origin of its position is under the border of the div (the border has been made transparent to help visualize this). - Background-origin set to
padding-box
(default) - Since thepadding-box
value is the default value, this should look the same as the default example. - Background-origin set to
content-box
- Notice how the background image has been shifted slightly down and right so that the origin of its position is the content area of the div, which is determined by the padding applied to the div.
Background-clip
- Background-clip set to
border-box
(default) - Here there is no difference from the default example since the background image's origin is the padding box (default) and the background-clip is set to border-box (default). In this case the image isn't being clipped since it fits within the border-box. - Background-clip set to
padding-box
- Here there is no difference from the default example since the background image's origin is the padding box (default) and the background-clip is set to padding-box. Like in the previous example the image isn't being clipped since it fits within the padding-box. - Background-clip set to
content-box
- Here you can see that the background is being clipped as the padding applied to the div creates a small content area. The origin of the background image is still the padding-box.
Background-clip and background-origin used together
- Background-clip set to
padding-box
and background-origin set tocontent-box
(both non-default values) - here you can see the origin of the image has been set to content-box so that it's pushed down and left from it's normal position by the div's padding. Then the background-clip has been set to padding-box so that the image does not show under the bottom or right border (it would if it were set to border-box).