Skip to content
Related Articles

Related Articles

Improve Article
HTML | DOM Style outlineWidth Property
  • Difficulty Level : Basic
  • Last Updated : 01 Aug, 2019

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"

Property Values:

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




    <!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
  • 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:




    <!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
  • thick: It sets the outline width to thick, the outline achieved is thicker than outline specified with width as medium and think.
    Example:




    <!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
  • length: It is used to define the outline width in terms of length units.
    Example:




    <!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
  • initial: It is used to set this property to its default value.
    Example:




    <!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
  • inherit: This inherits the property from its parent.
    Example:




    <!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
    • Internet Explorer
    • Firefox
    • Opera
    • Apple Safari



    My Personal Notes arrow_drop_up
Recommended Articles
Page :