The Wayback Machine - https://web.archive.org/web/20240930214658/https://www.geeksforgeeks.org/css-background-clip-property/
Open In App

CSS background-clip Property

Last Updated : 23 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The background-clip property in CSS controls how a background (color or image) extends within an element, allowing you to dictate the reach of your background.

Syntax:

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

Property value: 

  • border-box: The border-box property is used to set the background color spread over the whole division.
  • padding-box: The padding-box property is used to set the background inside the border.
  • content-box: The content-box property is used to set the background color up to the content only.
  • initial: It is the default value. It is used to set the background color spread over the whole division.

Examples of CSS background-clip Property

Example: In this example, we are using the background-clip: border-box property.

html
<!DOCTYPE html>
<html>
<head>
    <title>Border Box</title>
    <style>
        .gfg {
            background-color: green;
            background-clip: border-box;
            text-align: center;
            border: 10px dashed black;
        }
    </style>
</head>

<body>
    <div class="gfg">
        <h2>
            GeeksforGeeks
        </h2>
        <p>
            background-clip: border-box;
        </p>
    </div>
</body>
</html>

Output:

Example: In this example, we are using the background-clip: padding-box property.

html
<!DOCTYPE html>
<html>
<head>
    <title>padding-box property</title>
    <style>
        .gfg {
            background-color: green;
            background-clip: padding-box;
            padding: 25px;
            border: 10px dashed black;
        }
    </style>
</head>

<body style="text-align:center">

    <div class="gfg">
        <h2>
            GeeksforGeeks
        </h2>
        <p>
            background-clip: padding-box;
        </p>
    </div>
</body>
</html>

Output:

Example: In this example, we are using the background-clip: content-box property.

html
<!DOCTYPE html>
<html>
<head>
    <title>content-box property</title>
    <style>
        .gfg {
            background-color: green;
            background-clip: content-box;
            padding: 15px;
            border: 10px dashed black;
        }
    </style>
</head>

<body style="text-align:center">

    <div class="gfg">
        <h2>
            GeeksforGeeks
        </h2>
        <p>
            background-clip: content-box;
        </p>
    </div>
</body>
</html>

Output: 

Example: In this example, we are using the background-clip: initial-box property.

html
<!DOCTYPE html>
<html>
<head>
    <title>Initial</title>
    <style>
        .gfg {
            background-color: green;
            background-clip: initial;
            padding: 15px;
            border: 10px dashed black;
        }
    </style>
</head>

<body style="text-align:center">

    <div class="gfg">
        <h2>
            GeeksforGeeks
        </h2>
        <p>
            background-clip: initial;
        </p>
    </div>
</body>
</html>

Output:

Supported Browsers:

  • Google Chrome 1.0 and above
  • Edge 12.0 and above
  • Internet Explorer 9.0 and above
  • Firefox 4.0 and above
  • Opera 10.5 and above
  • Safari 14.0 and above

CSS background-clip Property – FAQs

What is the background-clip property in CSS?

The background-clip property in CSS defines how far the background image or color extends within an element. It determines whether the background is clipped to the content box, padding box, or border box.

How can background-clip be used to create transparent borders?

By setting background-clip: padding-box; and applying a transparent border color, you can create transparent borders while keeping the background color within the padding area. This is a popular technique for creating stylish borders.

What are the differences between border-box, padding-box, and content-box in background-clip?

  • border-box: The background extends behind the border.
  • padding-box: The background is confined within the padding area, not extending into the border.
  • content-box: The background is only applied within the content area, excluding padding and border.

Can background-clip be applied to text?

Yes, using background-clip: text;, you can apply background images or gradients to text, creating visually striking designs. This is commonly combined with webkit prefixes for broader support.

Why isn’t background-clip working as expected?

Common issues include browser compatibility (especially with text clipping) and incorrect box model settings. Ensure that the element has appropriate padding, borders, and content box configurations.



Previous Article
Next Article

Similar Reads

Tailwind CSS Background Clip
This class accepts more than one value in tailwind CSS in which all the properties are covered in class form. It is the alternative to the CSS background-clip property. This property is used to define how to extend background (color or image) within an element. Background Clip Classes: Class NameDescriptionbg-clip-borderThis class is used to set th
2 min read
CSS mask-clip property
The mask-clip CSS property specifies the area which is affected by the mask. Syntax: mask-clip: geometry-box values /* Or */ mask-clip: Keyword values /* Or */ mask-clip: Non-standard keyword values /* Or */ mask-clip: Multiple values /* Or */ mask-clip: Global values Property values: This property accepts values mentioned above and described below
2 min read
CSS clip-path Property
The clip-path property of CSS is used to clip the particular section of the image such that part of the image inside the section is shown and part of the image outside the section is not shown. and the CSS clip-path property allows you to create custom clipping paths to define the visible portion of an element. It can be used to create various shap
3 min read
Animation using clip-path property in CSS
The clip-path CSS property is used to clip the region in such a way that element in the clipped regions are shown. In this article, we will see how we can use the clip-path and @keyframes together to create an image animation. Step 1: Create a div with a class container that should include <img> tag. [GFGTABS] html <!DOCTYPE html> <h
2 min read
CSS clip Property
The clip property specifies defining what portion of an absolutely positioned element you want to make visible. Except for the specified region, the rest all other the regions are hidden. The clip property is only applicable to the absolutely positioned element ie., the element having the position: absolute or position: fixed. Syntax: clip: auto|sh
4 min read
HTML | DOM Style clip Property
The Style clip property in HTML DOM is used to set or return the visible part of a positioned element. Syntax: It returns the clip property.object.style.clipIt is used to set the clip property.object.style.clip = "rect(top right bottom left)|normal|initial| inherit" Note: This property has been deprecated. Return Values: It returns a string value,
3 min read
How to create a Triangle using CSS clip-path ?
In this article, we will see how we can create a triangle using CSS clip-path property. The CSS clip-path property is used to clip the particular section of the image such that the part of the image inside the section is shown and part of the image outside the section is not shown. Syntax: clip-path: <clip-source> | <basic-shape> | none
2 min read
How to add border in the clip-path: polygon() using CSS ?
Adding a border around shapes can substantially improve the visual attractiveness of your website when it comes to web design. Using the clip-path: polygon() Property is one great and inventive approach to accomplish this. This not only allows you to make unusual shapes but also allows you to add a border that fits your design. In this article, we
3 min read
How to Add a Clip Path to Image in Tailwind CSS ?
Web application designers can create creative and eye-catching designs with Tailwind CSS's flexibility in applying clip paths to images. Developers can create complex shapes by using clip paths, which define an element's visible region. Custom Clip Paths using TailwindTailwind CSS's custom clip paths allow developers to define unique shapes with CS
2 min read
Difference between background and background-color
Background Property The background property in CSS is very commonly used and contains many variants. The background property consists of all the following properties:background-colorbackground-imagebackground-positionbackground-sizebackground-repeatbackground-originbackground-clipbackground-attachmentExample: C/C++ Code &lt;style&gt; h1 { b
1 min read
HTML canvas clip() Method
The clip() method is used to clip a region/part of any shape and size from the given/original canvas. After clipping a region, the further drawings can be applied only on the clipped region. Although save() and restore() method can be used to get back to the previous canvas. Syntax: context.clip(); Example: <!DOCTYPE html> <html> <he
1 min read
jQuery UI Clip Effect
In this article, we are going to show the clip effect using jQuery UI. All the content will disappear from top and bottom at the same time when the action button is clicked which actually triggers the clip effect script. Syntax: $( ".selector" ).effect( selectedEffect, options, time(in ms), callback ); Parameters: selectedEffect: Effect selected by
2 min read
How to add Box-Shadow to The Clip-Path Object ?
As we all know that we can apply the shadow using the Box-Shadow attribute of CSS, but it is not valid if we apply it on the clipped Object using Clip-Path() function of CSS. Approach: We are going to create two divs, one for the main and the other for our clipped shape.Then we are going to use the drop-shadow() function to apply shadow effects. HT
2 min read
How to Play a Small Clip from a Long Video in HTML5?
Playing a specific clip from a longer video in HTML can enhance user experience and streamline content delivery. Sometimes, you may have a long video but only want to showcase a specific portion of it on your website. In such cases, playing a small clip from a longer video can be useful. HTML5 offers several approaches to achieve this seamlessly. M
3 min read
Which property is used to set the background image of an element using CSS ?
In this article, we will see the property used for setting the background image of an element in CSS. The background image can be set using the background-image property that is used to set one or more background images for an element. By default, it places the image in the top left corner. To specify two or more images, we need to specify the sepa
1 min read
CSS background-position-y Property
The CSS background-position-y property is used to set the initial vertical position for the background image i.e. it is used to set an image at a certain position in the vertical direction. The position is relative to the positioning later, which can be set by using the CSS background-origin property. Syntax: background-position-y: value; Property
2 min read
CSS background-position-x Property
The CSS background-position-x property is used to set the initial horizontal position for the background image i.e. it is used to set an image at a certain position in a horizontal direction. The position is relative to the positioning layer, which can be set by using the CSS background-origin property. Syntax: background-position-x: value; Propert
2 min read
How to use the background Property in CSS ?
The background property in CSS is a comprehensive shorthand property that allows you to set various background-related properties for an element. It's used to control the background color, image, position, size, and other related aspects. Syntax:/* Example of using the background property */.element { background: [background-color] [background-imag
1 min read
CSS background-attachment Property
The background-attachment property sets whether a background image scrolls with the rest of the page or is fixed. It has three possible values: scroll (default, the image moves with content), fixed (image stays in place), and `local` (image scrolls within the element). Syntaxbackground-attachment: scroll|fixed|local|initial|inherit;Property ValuePr
8 min read
CSS background-blend-mode Property
The background-blend-mode Property defines how the element's background image should blend with each other and with the element's background-color.  Syntax:  background-blend-mode: normal|multiply|screen|darken|lighten|color-dodge|saturation|difference|luminosity|overlay;Default Value:  normalProperty:Normal: This is the default value. It sets the
5 min read
CSS background-origin property
The background-origin property in CSS is your key to managing the background image of a webpage. It sets the origin point of the image in the background, with the default setting placing the background image origin at the upper-left corner of the screen/webpage. Syntax:  background-origin: padding-box|border-box|content-box|initial| inherit;Propert
5 min read
CSS background-repeat Property
The background-repeat property in CSS is used to repeat the background image both horizontally and vertically. It also decides whether the background-image will be repeated or not. Syntax: background-repeat: repeat|repeat-x|round|space|repeat-y|no-repeat|initial| inherit; Default Value: Its default value is initial.  Property Values: repeat: This p
3 min read
CSS background-color Property
The background-color CSS property sets the background color of an element, allowing you to create a solid color backdrop. You can define the color using named colors, hexadecimal values, RGB, RGBA, HSL, or HSLA. This property applies to both the content and padding areas of the element. By using the background-color property, you can easily enhance
4 min read
CSS background-image Property
The background-image property allows you to set one or more background images for an element. It allows you to specify the image URL and combine it with other background properties to control its position, size, repeat behavior, and more, enhancing the visual design of web pages. Syntaxelement_selector { background-image: url('image_url')| none | i
4 min read
CSS background-position Property
The CSS background-position property sets the starting position of a background image within an element. It allows you to use keywords, percentages, or length values to control where the image is placed. This property helps customize the visual layout by precisely aligning background images, enhancing the overall design and appearance of your webpa
7 min read
CSS background-size Property
The background-size property specifies the size of background images. It accepts values in pixels, percentages, or keywords such as cover (to ensure the image covers the entire element) and contain (to fit the image within the element), enabling flexible and responsive designs. Syntaxbackground-size: auto | length | cover | contain | initial | inhe
5 min read
Create a CSS Fireflies background using HTML/CSS
In this article, we will see how to create the CSS Fireflies background using HTML & CSS, along with understanding its implementation through the illustration. The CSS fireflies effect can be created by utilizing the CSS animation and we will implement 3 animations to achieve the fireflies effect. To create randomness, we used different animati
7 min read
HTML | DOM Style background Property
The Style background property in HTML DOM is a short hand property used to set or return the background of an element. It can help to manipulate one or more of eight background properties. Syntax: It returns the background property.object.style.backgroundIt is used to set the background property.object.style.background = "color image repeat attachm
7 min read
Web API HTMLBodyElement.background property
The HTML BodyElement.background property is used to returns a DOMString that represents the description of the location of the background image resource. Syntax: BodyElement.background Return Value: This property returns a DOMString that represents the description of the location of the background image resource. Example 1: C/C++ Code <!DOCTYPE
1 min read
jQWidgets jqxGauge LinearGauge background Property
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent and widely supported framework. jqxGauge represents a jQuery gauge widget, it is an indicator within a range of values. We can use gauges to show a value in a range of values in the data region, the
2 min read