Open In App

HTML | DOM Style outlineWidth Property

Improve
Improve
Like Article
Like
Save
Share
Report

The DOM Style outlineWidth property is used to set or return the width of the outline around an element. The outline is the line that is created around the specified element outside the border of the element to make the particular distinct and easier to distinguish.

Syntax:

  • It returns the outlineWidth property.
object.style.outlineWidth
  • It is used to set the outlineWidth property.
object.style.outlineWidth = "thin|medium|thick|length|initial|
inherit"

Return Values: It returns a string value, that represents the width of an element’s outline.

Property Values:

1. thin: It sets the outline width to thin, the outline achieved is thinner than outline specified with width as medium and thick.

Example: 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Style outlineWidth Property
    </title>
    <style>
        .elem {
            outline-style: dashed;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style OutlineWidth</b>
    <p class="elem">
        GeeksforGeeks is a computer science portal
        with a huge variety of well written and
        explained computer science and programming
        articles, quizzes and interview questions.
        The portal also has dedicated GATE preparation
        and competitive programming sections.
    </p>
    <button onclick="changeWidth()">
        Change outlineWidth
    </button>
    <!--Script to change the outline width -->
    <script>
        function changeWidth() {
            elem = document.querySelector('.elem');
            elem.style.outlineWidth = 'thin';
        }
    </script>
</body>
</html>


Output:

  • Before clicking the button:

 thin_before

  • After clicking the button:

 thin_after

2. medium: It sets the outline width to default. The width of the outline is thinner than the outline sets thick and thicker than the outline set as thin. 

Example: 

HTML




<!DOCTYPE html>
<html
<head>
    <title>
        DOM Style outlineWidth Property
    </title>
 
    <style>
        .elem {
            outline-style: dashed;
            outline-width: thin;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style OutlineWidth</b>
    <p class="elem">
        GeeksforGeeks is a computer science portal
        with a huge variety of well written and
        explained computer science and programming
        articles, quizzes and interview questions.
        The portal also has dedicated GATE preparation
        and competitive programming sections.
    </p>
    <button onclick="changeWidth()">
        Change outlineWidth
    </button>
    <!--Script to change the outline width -->
    <script>
        function changeWidth() {
            elem = document.querySelector('.elem');
            elem.style.outlineWidth = 'medium';
        }
    </script>
</body>
</html>


Output:

  • Before clicking the button:

 medium-before

  • After clicking the button:

 medium-after

3. thick: It sets the outline width to thick, the outline achieved is thicker than outline specified with width as medium and think.

Example: 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Style outlineWidth Property
    </title>
    <style>
        .elem {
            outline-style: dashed;
        }
    </style>
</head>
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style OutlineWidth</b>
    <p class="elem">
        GeeksforGeeks is a computer science portal
        with a huge variety of well written and
        explained computer science and programming
        articles, quizzes and interview questions.
        The portal also has dedicated GATE preparation
        and competitive programming sections.
    </p>
    <button onclick="changeWidth()">
        Change outlineWidth
    </button>
    <!--Script to change the outline width -->
    <script>
        function changeWidth() {
            elem = document.querySelector('.elem');
            elem.style.outlineWidth = 'thick';
        }
    </script>
</body>
</html>


Output:

  • Before clicking the button:

 thick-before

  • After clicking the button:

 thick-after

4. length: It is used to define the outline width in terms of length units. 

Example: 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Style outlineWidth Property
    </title>
    <style>
        .elem {
            outline-style: dashed;
        }
    </style>
</head>
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style OutlineWidth</b>
    <p class="elem">
        GeeksforGeeks is a computer science portal
        with a huge variety of well written and
        explained computer science and programming
        articles, quizzes and interview questions.
        The portal also has dedicated GATE preparation
        and competitive programming sections.
    </p>
    <button onclick="changeWidth()">
        Change outlineWidth
    </button>
    <!--Script to change the outline width -->
    <script>
        function changeWidth() {
            elem = document.querySelector('.elem');
            elem.style.outlineWidth = '10px';
        }
    </script>
</body>
</html>


Output:

  • Before clicking the button:

 length-before

  • After clicking the button:

 length-after

5. initial: It is used to set this property to its default value. 

Example: 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Style outlineWidth Property
    </title>
    <style>
        .elem {
            outline-style: dashed;
            outline-width: 4px;
        }
    </style>
</head>
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style OutlineWidth</b>
    <p class="elem">
        GeeksforGeeks is a computer science portal
        with a huge variety of well written and
        explained computer science and programming
        articles, quizzes and interview questions.
        The portal also has dedicated GATE preparation
        and competitive programming sections.
    </p>
    <button onclick="changeWidth()">
        Change outlineWidth
    </button>
    <!--Script to change the outline width -->
    <script>
        function changeWidth() {
            elem = document.querySelector('.elem');
            elem.style.outlineWidth = 'initial';
        }
    </script>
</body>
</html>


Output:

  • Before clicking the button:

 initial-after

  • After clicking the button:

 initial-after

6. inherit: This inherits the property from its parent. 

Example: 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Style outlineWidth property
    </title>
    <style>
        #parent {
            padding: 10px;
            outline-style: dashed;
 
            /* Set the outlineWidth of
            parent element */
            outline-width: 5px;
        }
        .elem {
            outline-style: dotted;
        }
    </style>
</head>
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style OutlineWidth</b>
    <br><br>
    <div id="parent">
        <p class="elem">
            GeeksforGeeks is a computer science portal
            with a huge variety of well written and
            explained computer science and programming
            articles, quizzes and interview questions.
            The portal also has dedicated GATE preparation
            and competitive programming sections.
        </p>
    </div>
    <br>
    <button onclick="changeWidth()">
        Change outlineWidth
    </button>
    <!-- Script to change the outline width -->
    <script>
        function changeWidth() {
            elem = document.querySelector('.elem');
            elem.style.outlineWidth = 'inherit';
        }
    </script>
</body>
</html>


Output:

  • Before clicking the button:

 inherit-before

  • After clicking the button:

 inherit-after

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

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 8
  • Firefox 1.5
  • Opera 7
  • Apple Safari 1.2


Last Updated : 08 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads