HTML DOM Style clip Property


The HTML DOM style clip property is used for setting or getting the positioned element visible part.

Following is the syntax for −

Setting the clip property −

object.style.clip = "auto|rect(top right bottom left)|initial|inherit"

The above properties are explained as follows −

ValueDescription
autoThe element doesn’t clip and this is the default value.
rect(top right bottom left)It clips the shape according to the given four coordinates.
initialFor setting this property to initial value.
inheritTo inherit the parent property value

Let us look at an example for the clip property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   div{
      position:relative;
   }
   #IMG1{
      width:200px;
      height:200px;
      position:absolute;
   }
   #P1{
      position:absolute;
      margin-top:210px;
   }
   button{
      margin-top: 250px;
   }
</style>
<script>
   function changeClip(){
      document.getElementById("IMG1").style.clip="rect(0px 75px 75px 0px)";
      document.getElementById("Sample").innerHTML="The image clip property is changed now ";
   }
</script>
</head>
<body>
   <div >
      <img id="IMG1" src="https://www.tutorialspoint.com/hibernate/images/hibernate-mini-logo.jpg">
      <p id="P1">Change the above image clip property by clicking the below button</p>
      <button onclick="changeClip()">Change Clip</button>
      <p id="Sample"></p>
   </div>
</body>
</html>

Output

On clicking the “Change Clip” button −

Updated on: 07-Jul-2020

24 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements