CSS Portal

CSS background-clip Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The CSS property background-clip defines the area within which a background is painted. By default, backgrounds are applied to the entire border box of an element, but with background-clip, you can restrict the background to only specific regions such as the content, padding, or border area. This allows for more precise control over how background colors, gradients, or images appear in relation to an element’s shape and spacing. It’s particularly useful when you combine it with properties like border-radius, as you can prevent the background from bleeding into the rounded corners, maintaining a clean visual separation between the element’s edges and its background.

Using background-clip can also enhance complex designs where layering and visual hierarchy are important. For example, when a background is applied to an element with significant padding, clipping it to the content box can emphasize the inner content while leaving the padding area transparent or unaffected. Similarly, when working with borders, clipping the background to the padding box ensures that the border itself stands out without being visually merged with the background, creating a sharper and more defined layout. This is often combined with background-origin, which determines the starting position of the background, allowing for nuanced control over both placement and coverage.

Another practical application of background-clip is in creative text or shape effects. When used with transparent or partially transparent backgrounds, you can make the background appear only within certain regions, achieving effects like “highlighted” content or textured fills within text blocks. This can also interact with pseudo-elements to create layered visual effects without additional markup. Overall, background-clip is a subtle but powerful property that gives designers precise control over how and where backgrounds appear, enhancing both aesthetics and functional design in modern web layouts.

Definition

Initial value
border-box
Applies to
All elements
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.backgroundClip

Interactive Demo

This is the content of the element.

Syntax

background-clip: <box> [ , <box> ]* 

Values

<box> = border-box | padding-box | content-box
  • border-boxThe background extends to the outside edge of the border (but underneath the border in z-ordering).
  • padding-boxNo background is drawn below the border (background extends to the outside edge of the padding).
  • content-boxThe background is painted within (clipped to) the content box.

Example

<div class='wrapper'>
<h1 class='gradient-text'>Gradient Text - background-clip: text</h1>

<div class='grid'>
<div class='box border'>background-clip: border-box</div>
<div class='box padding'>background-clip: padding-box</div>
<div class='box content'>background-clip: content-box</div>
</div>
</div>
/* Layout and base styles */
:root {
  --bg-dark: #071023;
  --card-width: 260px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 32px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: linear-gradient(180deg, #0b1220 0%, var(--bg-dark) 100%);
  color: #e6eef8;
}

.wrapper {
  max-width: 980px;
  margin: 0 auto;
}

/* background-clip: text example (requires WebKit prefix for many browsers) */
.gradient-text {
  font-size: 48px;
  margin: 0 0 24px;
  background: linear-gradient(90deg, #ff8a00, #e52e71, #6a11cb);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

/* Example cards showing different background-clip values */
.grid {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.box {
  width: var(--card-width);
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-weight: 700;
  text-align: center;
  border: 12px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(135deg, #ff7a18, #af002d 45%, #319197 100%);
  color: #fff;
}

/* Paints under the border (background fills border area) */
.box.border {
  background-clip: border-box;
}

/* Paints only the padding and content areas  -  not under the border */
.box.padding {
  background-clip: padding-box;
  padding: 16px;
}

/* Paints only the content area  -  padding and border remain transparent */
.box.content {
  background-clip: content-box;
  padding: 20px;
}

Browser Support

The following information will show you the current browser support for the CSS background-clip property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!