background-clip

Sets which area of the element the background extends to, including the text background effect.

Initial value
border-box
Inherited
No
Animatable
no
Applies to
all elements
JavaScript
element.style.backgroundClip = "padding-box"
On this page

Example

#
CSS
.gradient-title {
  background: linear-gradient(90deg, #a78bfa, #38bdf8);
  background-clip: text;
  color: transparent;
}
Preview

Definition and usage

#

The background-clip property clips the background to the chosen area. border-box (the default) draws the background under the border too, padding-box ends it at the inner edge of the border, and content-box draws it only under the content.

The most striking value is text: the background is visible only in the shape of the letters. Combined with a gradient and a transparent text colour, it gives the popular coloured-heading effect.

The difference between border-box and padding-box is easiest to see with a dashed or semi-transparent border.

Syntax

#
Syntax
background-clip: border-box | padding-box | content-box | text;

Values

#
  • border-box

    The background extends under the border.
  • padding-box

    The background ends at the border.
  • content-box

    The background only under the content, without the padding.
  • text

    The background is visible only in the letters. The text must have a transparent colour.

Values in practice

#

border-box

The background extends under the border.
.demo { background-clip: border-box; }

padding-box

The background ends at the border.
.demo { background-clip: padding-box; }

content-box

The background only under the content, without the padding.
.demo { background-clip: content-box; }

text

The background is visible only in the letters. The text must have a transparent colour.
.demo { background: linear-gradient(90deg, #f59e0b, #f43f5e, #7c3aed); background-clip: text; color: transparent; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • For text with a gradient background also set color: transparent, otherwise the text colour will cover the background.
  • Older browsers required -webkit-background-clip: text. It is worth adding that line alongside if backward compatibility matters to you.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.