HTML DOM Style backgroundClip Property


The backgroundClip property lets us control how far the background image will be painted i.e. the painting area of the background image. It is used for setting or returning that painting area.

Syntax

Following is the syntax for −

Setting the backgroundClip property −

background-clip: border-box | padding-box | content-box

Values

Following are the values −

Sr.NoValue & Description
1border-box
This clips the background within the border-box and this is the default value.
2padding-box
This clips the background within the padding box.
3content-box
The background is clipped within the content box.

Example

Let us look at an example for the backgroundclip property −

<!DOCTYPE html>
<html>
<head>
<style>
   #one {
      box-shadow: 0 0 2px black;
      padding: 18px;
      background: skyblue;
      background-clip: content-box;
   }
</style>
<script>
   function changeBackClip(){
      document.getElementById("one").style.backgroundClip="padding-box";
      document.getElementById("Sample").innerHTML="The background clip property is now padding-box";
      background-clip: border-box | padding-box | content-box
   }
</script>
</head>
<body>
<div id="one">
Phasellus eu justo lectus. Praesent et nulla facilisis, venenatis justo eget, tempor lectus.
Integer ut felis vel lectus convallis fermentum. Fusce ut felis mauris.</div>
<p>Change the above div background-clip value by clicking the below button</p>
<button onclick="changeBackClip()">CHANGE CLIP</button>
<p id="Sample"></p>
</body>
</html>

Output

This will produce the following output −

On clicking the CHANGE CLIP button −

Updated on: 20-Aug-2019

24 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements