Open In App

CSS background-clip Property

The background-clip property in CSS is a powerful tool that dictates how a background (be it color or image) extends within an element. It’s all about controlling the reach of your background.

Syntax:

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

Property value: 

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

<!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.

<!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.

<!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.

<!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:

Article Tags :