W3cubDocs

/CSS

background-clip

The background-clip CSS property sets whether an element's background <color> or <image> extends underneath its border.

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.

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

Initial value border-box
Applies to all elements. It also applies to ::first-letter and ::first-line.
Inherited no
Media visual
Computed value as specified
Animation type discrete
Canonical order the unique non-ambiguous order defined by the formal grammar

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 1
1
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: padding, border, and content.
12 4
4
49
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: padding, border, and content.
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
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: padding, border, and content.
3
3
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: 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 Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows in the clipping.
15
15
12
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows 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.
No Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows in the clipping.
Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows in the clipping.
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 4.1
4.1
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: padding, border, and content.
Yes
Yes
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: padding, border, and content.
Yes 14
14
49
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: padding, border, and content.
12.1
12.1
14
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Webkit also supports the prefixed version of this property, and in that case, in addition to the current keywords, the alternative synonyms are: padding, border, and content.
Yes Yes
content-box 4.1 Yes Yes 14 12.1 Yes Yes
text Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows in the clipping.
Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows in the clipping.
Yes 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.
Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows in the clipping.
Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support the prefixed version of the property only; according to the official blog, WebKit does not include text decorations or shadows in the clipping.
?

See also

© 2005–2018 Mozilla Developer Network 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