CSS background-clip Property

CSS background-clip property specifies how far an element’s background color or image should extend within the element.

The background color/image can extend up to its content-box or border-box or padding-box. See the example below:

Example:

div{
   background: lightgreen;
   background-clip: content-box;
   border: 10px dashed red;
   height: 100px;
   padding: 20px;
}

Similar to the background color, you can apply the background-clip property to the background image also. See the example below:

Example:

div{
   background-image: url('images/sand.jpg');
   background-clip: content-box;
   border: 10px dashed red;
   padding: 20px;
}

CSS Syntax

The background-clip property has the following syntax:

background-clip: border-box|padding-box|content-box|initial|inherit;

Property Values

The background-clip property accepts the following values:

border-boxThe background color/image extends to the outside edge of the element’s border. This is the default value.
padding-boxThe background color/image extends to the inside edge of the element’s border.
content-boxThe background color/image extends to the boundary of the element’s content area.
initialSets the background-clip property to its default value(border-box).
inheritInherits the background-clip property from the parent element.

General Info

Default Valueborder-box
InheritedNo
JavaScript Usageelement.style.backgroundClip = “content-box”

Related Pages

CSS Tutorial: CSS Background

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

Leave a Comment