HTML | DOM Style outline Property

The Style outline property in HTML DOM is used to set or return all outline properties in one declaration. This property draws a line around an element. It sets or returns the one or more border property in short form.
The outline can be set the following properties:

  • outline-width
  • outline-style
  • outline-color

Syntax:

  • It returns the outline property.
    object.style.outline
  • It is used to set the outline property.
    object.style.outline = "width|style|color|initial|inherit"

Property Values:



  • width:It sets the outline width.
  • style:It sets the style of outline.
  • color:It sets the color of the outline.
  • Initial: It sets the DOM outline property to its default value.
  • Inherit: The element inherits its property from parent element.

Example 1: Add a thick solid blue outline around the div container.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        HTML DOM Style outline Property
    </title>
</head>
  
<body>
    <div id = "container">
        <h1>GeeksforGeeks</h1>
          
        <h2>DOM Style outline Property</h2>
    </div>
  
    <script>
        function myGeeks() {
            document.getElementById("container").style.outline
                    = "thick solid blue";
        }
        myGeeks();
    </script>
</body>
  
</html>                    

chevron_right


Output:

Example 2: Add a length dashed green outline around the div container.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        HTML DOM Style outline Property
    </title>
    <style>
    #container {
        border: 3px solid black;
        outline: 3px solid blue;
    }
    </style>
</head>
  
<body>
    <div id = "GFG">
        <h1>GeeksforGeeks</h1>
          
        <h2>DOM Style outline Property</h2>
    </div>
      
    <button onclick = "myGeeks()">
        Click Here!
    </button>
      
    <!-- script to set outline style -->
    <script>
        function myGeeks() {
            document.getElementById("GFG").style.outline
                    = "7px dashed green";
        }
    </script>
</body>
  
</html>                    

chevron_right


Output:

  • Before Click on the button:
  • After Click on the button:

Supported Browsers: The browser supported by DOM Style outline property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.