background-clip CSS property

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

The background-clip CSS property sets whether an element's background extends underneath its border box, padding box, or content box.

Try it

background-clip: border-box;
background-clip: padding-box;
background-clip: content-box;
background-clip: text;
color: transparent;
text-shadow: none;
<section id="default-example">
  <div id="example-element">This is the content of the element.</div>
</section>
#example-element {
  background-image: url("../../../../../../shared-assets/images/examples/leopard.jpg");
  color: white;
  text-shadow: 2px 2px black;
  padding: 20px;
  border: 10px dashed #333333;
  font-size: 2em;
  font-weight: bold;
}

Syntax

css
/* Keyword values */
background-clip: border-box;
background-clip: padding-box;
background-clip: content-box;
background-clip: text;
background-clip: border-area;

/* Global values */
background-clip: inherit;
background-clip: initial;
background-clip: revert;
background-clip: revert-layer;
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.

border-area

The background is painted within (clipped to) the area painted by the border, taking border-width and border-style into account but ignoring any transparency introduced by border-color.

Description

The background is always drawn behind the border, so background-clip: border-box has a visual effect only when the border is partially opaque or has transparent or partially opaque regions. Also, the background-clip: text property has little to no visual effect if the text is fully or partially opaque.

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.

Accessibility

When using background-clip: text, check that the contrast ratio between the background color and the color of the text placed over it is high enough that people experiencing low vision conditions will be able to read the content of the page.

If the background image does not load, this could also lead to the text becoming unreadable. Add a fallback background-color to prevent this from happening, and test without the image.

Consider using feature queries with @supports to test for support of background-clip: text and provide an accessible alternative where it is not supported.

Formal definition

Initial valueborder-box
Applies toall elements. It also applies to ::first-letter and ::first-line.
Inheritedno
Computed valueas specified
Animation typea repeatable list

Formal syntax

background-clip = 
<bg-clip>#

<bg-clip> =
<visual-box> |
[ border-area || text ]

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

Examples

HTML

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>
<p class="border-area">
  The background is clipped to the area painted by the border.
</p>

CSS

css
p {
  border: 0.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;
  color: rgb(0 0 0 / 20%);
}

.border-area {
  background-clip: border-area;
  border-color: transparent;
}

Result

Specifications

Specification
CSS Backgrounds and Borders Module Level 3
# background-clip
CSS Backgrounds Module Level 4
# background-clip

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
background-clip
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Chrome accepts alternate synonyms to its values: padding, border, and content.
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Since Edge 79, accepts alternate synonyms to its values: padding, border, and content.
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Partial support
Firefox 1 – 3.6 (Release date: 2004-11-09)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -moz-
footnote Used the -moz-background-clip: padding | border syntax.
Firefox – Full support
Firefox 49 (Release date: 2016-09-20)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Opera accepts alternate synonyms to its values: padding, border, and content.
Opera – Full support
Opera 10.5 (Release date: 2010-03-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Safari accepts alternate synonyms to its values: padding, border, and content.
Safari – Full support
Safari 5 (Release date: 2010-06-07)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Chrome Android accepts alternate synonyms to its values: padding, border, and content.
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 49 (Release date: 2016-09-20)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Opera accepts alternate synonyms to its values: padding, border, and content.
Opera Android – Full support
Opera Android 11 (Release date: 2011-03-22)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Safari accepts alternate synonyms to its values: padding, border, and content.
Safari on iOS – Full support
Safari on iOS 5 (Release date: 2011-10-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Samsung Internet accepts alternate synonyms to its values: padding, border, and content.
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote WebView Android accepts alternate synonyms to its values: padding, border, and content.
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Safari accepts alternate synonyms to its values: padding, border, and content.
WebView on iOS – Full support
WebView on iOS 5 (Release date: 2011-10-12)
footnote Full support
border-area
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera
footnote No support
Safari – Full support
Safari 18.2 (Release date: 2024-12-11)
footnote Full support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – Full support
Safari on iOS 18.2 (Release date: 2024-12-11)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 18.2 (Release date: 2024-12-11)
footnote Full support
border-box
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 2 (Release date: 2008-07-11)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 2 (Release date: 2008-07-11)
footnote Full support
content-box
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
footnote Full support
Opera – Full support
Opera 10.5 (Release date: 2010-03-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 11 (Release date: 2011-03-22)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
padding-box
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 2 (Release date: 2008-07-11)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 2 (Release date: 2008-07-11)
footnote Full support
text
Chrome – Partial support
Chrome 3 – 119 (Release date: 2009-09-15)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip; see bug 40229927).
Chrome – Full support
Chrome 120 (Release date: 2023-12-05)
footnote Full support
Edge – Partial support
Edge 12 – 14 (Release date: 2015-07-29)
footnote Partial support
footnote Before Edge 15, this value was supported with the prefixed version of the property only.
Edge – No support
Edge 15 – 18 (Release date: 2017-04-05)
unknown Support unknown
Edge – Partial support
Edge 79 – 119 (Release date: 2020-01-15)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip; see bug 40229927).
Edge – Full support
Edge 120 (Release date: 2023-12-07)
footnote Full support
Firefox – Partial support
Firefox 49 (Release date: 2016-09-20)
footnote Partial support
footnote Does not work with background-attachment: fixed (bug 1313757), in multi-layer backgrounds with other values (bug 1481498), and in some other special cases (see bug 1656784).
Opera – Partial support
Opera 15 – 105 (Release date: 2013-07-02)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip; see bug 40229927).
Opera – Full support
Opera 106 (Release date: 2023-12-19)
footnote Full support
Safari – Partial support
Safari 4 – 13.1 (Release date: 2009-06-08)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip).
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Partial support
Chrome Android 18 – 119 (Release date: 2012-06-27)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip; see bug 40229927).
Chrome Android – Full support
Chrome Android 120 (Release date: 2023-12-05)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 49 (Release date: 2016-09-20)
footnote Partial support
footnote Does not work with background-attachment: fixed (bug 1313757), in multi-layer backgrounds with other values (bug 1481498), and in some other special cases (see bug 1656784).
Opera Android – Partial support
Opera Android 14 – 79 (Release date: 2013-05-21)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip; see bug 40229927).
Opera Android – Full support
Opera Android 80 (Release date: 2024-01-25)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 3.2 – 13.4 (Release date: 2010-04-03)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip).
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 1 – 24 (Release date: 2013-04-27)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip; see bug 40229927).
Samsung Internet – Full support
Samsung Internet 25 (Release date: 2024-04-24)
footnote Full support
WebView Android – Partial support
WebView Android 4.4 – 119 (Release date: 2013-12-09)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip; see bug 40229927).
WebView Android – Full support
WebView Android 120 (Release date: 2023-12-05)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 3.2 – 13.4 (Release date: 2010-04-03)
footnote Partial support
footnote The text value is only supported by -webkit-background-clip (and not by background-clip).
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also