HTML DOM Style isolation Property


The HTML DOM style isolation property is for defining if the element must create a new stacking content or not. This property is mainly used for preventing the element from blending in the background by creating a separate stack element.

Following is the syntax for −

Setting the isolation property −

object.style.isolation = "auto|isolate|initial|inherit"

The above properties are explained as follows −

Value
Description
auto
Thisis default property for setting the height.
length
Thisis for defining the height in length units.
%
Fordefining the height relative to parent element in percentage.
initial
Forsetting this property to initial value.
inherit
Toinherit the parent property value

Let us look at an example for the isolation property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   #demo{
      background-color: lightpink;
      width: 250px;
      height: 250px;
   }
   #demo2{
      width: 100px;
      height: 100px;
      border: 3px solid red;
      padding: 4px;
      mix-blend-mode:difference;
   }
</style>
<script>
   function changeIsolation() {
      document.getElementById("demo1").style.isolation="isolate";
      document.getElementById("Sample").innerHTML="The inner div has now been isolated";
   }
</script>
</head>
<body>
   <div id="demo">
   <div id="demo1">
   <div id="demo2">
      INNER DIV
   </div>
   </div>
   </div>
   <p>Change the isolation mode for the inner div by clicking the below button</p>
   <button onclick="changeIsolation()">Change Isolation</button>
   <p id="Sample"></p>
</body>
</html>

Output

On clicking the “Change Isolation” button −

Updated on: 24-Oct-2019

86 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements