CSS Background-Clip Property

Background-Clip Property

The CSS background-clip property defines how far a background should extend within an element.

There are several possible values:

Examples

HTML

<div class="example1">
    <p>border-box</p>
</div>

<br>

<div class="example2">
    <p>padding-box</p>
</div>

<br>

<div class="example3">
    <p>content-box</p>
</div>

CSS

.example1 {
    border: 1em dashed black;
    padding: 10px;
    background: yellow;
    background-clip: border-box;
    width: 200px;
}

.example2 {
    border: 1em dashed black;
    padding: 10px;
    background: yellow;
    background-clip: padding-box;
    width: 200px;
}

.example3 {
    border: 1em dashed black;
    padding: 10px;
    background: yellow;
    background-clip: content-box;
    width: 200px;
}

border-box


padding-box


content-box