Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Colors and Backgrounds

The background-clip property

Reference for CSS background-clip: border-box, padding-box, content-box and text, gradient text, how it differs from background-origin, and live examples.

The background-clip property decides how far a background (its color and images) is painted. By default it extends under the border to the outer edge of the border box. Clipping it to the padding box or content box trims the background, and the value text clips it to the shapes of the element's text.

The last one is the basis of gradient text: you paint a gradient background, clip it to the glyphs and make the actual text color transparent.

CSS
.card { background-clip: padding-box; }
.gradient-text {
  background-image: linear-gradient(90deg, #f97316, #db2777);
  background-clip: text;
  color: transparent;
}

Try it

Painting areas and gradient text

Syntax

CSS
background-clip: <bg-clip>#;

<bg-clip> = border-box | padding-box | content-box | text

background-clip: text;
background-clip: padding-box, border-box; /* two layers */
  • Initial value: border-box
  • Applies to: all elements
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
border-box Paints out to the outer edge of the border (under the border). The default.
padding-box Stops at the inner edge of the border. Nothing is painted under it.
content-box Paints only the content area, inside the padding.
text Paints only where the element's text (and its descendants' text) is drawn.

Usage notes

  • Why borders look odd. With translucent, dotted or dashed borders the background shows through the gaps. Switch to padding-box for a clean edge.
  • Gradient text recipe. You need a background image, background-clip: text and a transparent color. Keep a solid color as a fallback in case the clip is unsupported, then override it inside @supports (background-clip: text).
  • Unprefixed text works in current browsers. Older WebKit-based browsers required -webkit-background-clip: text; including both costs nothing.
  • Accessibility of gradient text. A text color of transparent can vanish in forced-colors mode and in print. The gradient must keep enough contrast against the page background everywhere along the text.
  • Setting it with the shorthand. A single box in background sets both origin and clip, and the shorthand resets clip. Write background-clip after the shorthand, especially for text.
  • Not the same as background-origin. Origin positions the image; clip only hides the parts outside the chosen box.
  • Newer values. The specification adds border-area, which paints only the border region. Check a compatibility table before using it.

Browser support

The three box values are supported in every browser. text is supported unprefixed in current browsers and with the -webkit- prefix in older ones.