Javascript DOM CSS Style outlineOffset Property

Introduction

Move the outline border 15 pixels outside the border edge:

document.getElementById("myDIV").style.outlineOffset = "15px";

Click the button to change the outline-offset property of the DIV element:

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {//from  w w w.  j  a  va2s. co m
  margin: auto;
  border: 1px solid black;
  outline: coral solid 5px;
  width: 300px;
  height: 300px;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="myDIV">
  <h1>Hello</h1>
</div>
<script>
function myFunction() {
  document.getElementById("myDIV").style.outlineOffset = "15px";
}
</script>

</body>
</html>

The outlineOffset property offsets an outline, and draws it beyond the border edge.

Outlines differ from borders in two ways:

  • Outlines do not take up space
  • Outlines may be non-rectangular

Property Values

Value Description
length The distance the outline is outset from the border edge. Default to 0
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The outlineOffset property returns a String representing the outline-offset property of an element.




PreviousNext

Related