The background-clip
CSS property sets whether an element's background extends underneath its border box, padding box, or content box.
If the element has no background-image
or background-color
, this property will only have a visual effect when the border has transparent regions or partially opaque regions (due to border-style
or border-image
); otherwise, the border masks the difference.
Note: Because the root element has a different background painting area, the background-clip
property has no effect when specified on it. See "The backgrounds of special elements."
Note: For documents whose root element is an HTML element: if the computed value of background-image
on the root element is none
and its background-color
is transparent
, user agents must instead propagate the computed values of the background
properties from that element’s first HTML <body>
child element. The used values of that <body>
element’s background
properties are their initial values, and the propagated values are treated as if they were specified on the root element. It is recommended that authors of HTML documents specify the canvas background for the <body>
element rather than the HTML element.
/* Keyword values */ background-clip: border-box; background-clip: padding-box; background-clip: content-box; background-clip: text; /* Global values */ background-clip: inherit; background-clip: initial; background-clip: unset;
border-box
padding-box
content-box
text
Initial value | border-box |
---|---|
Applies to | all elements. It also applies to ::first-letter and ::first-line . |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
<box>#where
<box> = border-box | padding-box | content-box
<p class="border-box">The background extends behind the border.</p> <p class="padding-box">The background extends to the inside edge of the border.</p> <p class="content-box">The background extends only to the edge of the content box.</p> <p class="text">The background is clipped to the foreground text.</p>
p { border: .8em darkviolet; border-style: dotted double; margin: 1em 0; padding: 1.4em; background: linear-gradient(60deg, red, yellow, red, yellow, red); font: 900 1.2em sans-serif; text-decoration: underline; } .border-box { background-clip: border-box; } .padding-box { background-clip: padding-box; } .content-box { background-clip: content-box; } .text { background-clip: text; -webkit-background-clip: text; color: rgba(0,0,0,.2); }
Specification | Status | Comment |
---|---|---|
CSS Backgrounds and Borders Module Level 3 The definition of 'background-clip' in that specification. | Candidate Recommendation | Initial definition. |
CSS Backgrounds and Borders Module Level 4 The definition of 'background-clip' in that specification. | Editor's Draft | Add text value. |
Desktop | ||||||
---|---|---|---|---|---|---|
background-clip |
1
|
12 | 4
|
9
|
10.5
|
3
|
content-box |
1 | 12 | 4 | 9
|
10.5 | 3 |
text |
3
|
15
|
49
|
No | 15
|
4
|
Mobile | ||||||
---|---|---|---|---|---|---|
background-clip |
4.1
|
18
|
14
|
11
|
1
|
1.0
|
content-box |
4.1 | 18 | 14 | 11 | 1 | 1.0 |
text |
≤37
|
18
|
49
|
14
|
3.2
|
1.0
|
clip-path
property creates a clipping region that defines what part of an entire element should be displayed.background
, background-color
, background-image
, background-origin
© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip