W3cubDocs

/CSS

background-clip

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.

Syntax

/* 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;

Values

border-box
The background extends to the outside edge of the border (but underneath the border in z-ordering).
padding-box
The background extends to the outside edge of the padding. No background is drawn beneath the border.
content-box
The background is painted within (clipped to) the content box.
text
The background is painted within (clipped to) the foreground text.

Formal definition

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

Formal syntax

<box>#

where
<box> = border-box | padding-box | content-box

Examples

HTML

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

CSS

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);
}

Result

Specifications

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
background-clip 1
1
1 — 64
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome accepts alternate synonyms to its values: padding, border, and content.
12 4
4
49
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
1 — 4
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
Used the -moz-background-clip: padding | border syntax.
9
9
In IE 7 and IE 8 of Internet Explorer, this property always behaved like background-clip: padding when overflow was hidden, auto, or scroll.
10.5
10.5
15 — 51
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Opera accepts alternate synonyms to its values: padding, border, and content.
3
Prefixed
3
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari accepts alternate synonyms to its values: padding, border, and content.
content-box 1 12 4 9
9
In IE 7 and IE 9 of Internet Explorer, it always behaved like background-clip: padding if overflow: hidden | auto | scroll
10.5 3
text 3
3
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.
15
15
12
Before Edge 15, this value was supported with the prefixed version of the property only.
49
49
48
Disabled
Disabled From version 48: this feature is behind the layout.css.background-clip-text.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No 15
15
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.
4
4
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
background-clip 4.1
4.1
≤37 — 64
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
WebView accepts alternate synonyms to its values: padding, border, and content.
18
18
18 — 64
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome accepts alternate synonyms to its values: padding, border, and content.
14
14
49
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
11
11
14 — 47
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Opera accepts alternate synonyms to its values: padding, border, and content.
1
Prefixed
1
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari accepts alternate synonyms to its values: padding, border, and content.
1.0
1.0
1.0 — 9.0
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome accepts alternate synonyms to its values: padding, border, and content.
content-box 4.1 18 14 11 1 1.0
text ≤37
≤37
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.
18
18
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.
49
49
48
Disabled
Disabled From version 48: this feature is behind the layout.css.background-clip-text.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
14
14
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.
3.2
3.2
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.
1.0
1.0
This value is supported with the prefixed version of the property only.
According to the WebKit blog, text decorations or shadows are not included in the clipping.

See also

© 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