HTML | DOM Style outlineWidth Property

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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    • Before clicking the button:
      initial-after
    • After clicking the button:
      initial-after
  • inherit: This inherits the property from its parent.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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

    Technical Writer Lets have an update

    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.



    Improved By : shubham_singh



    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.