HTML | DOM Style letterSpacing Property

The Style letterSpacing property in HTML DOM is used to set the space between the characters. This property allows to set the required space between characters and also used to returns the space between characters.

Syntax:

  • It returns the letterSpacing property.
    object.style.letterSpacing
  • It used to set the letterSpacing property.
    object.style.letterSpacing = "normal|length|initial|inherit"

Property Values:



  • normal: The normal spacing for the current font i.e no extra space between characters. This is the default value.
  • length: This mode specifies extra inter-character space in addition to the default space between the characters. Negative values are also allowed.
  • initial: It sets the letterSpacing property to its default value.
  • inherit: This property is inherited from its parent element.

Return Value: It returns a string that represents a space between the characters.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            DOM Style letterSpacing Property 
        </title
    </head
      
    <body
        <center
            <h1 style = "color:green;"
                GeeksForGeeks 
            </h1
              
            <h2>DOM Style letterSpacing Property </h2>    
              
            <p id = "GFG">
                A computer science portal for geeks
            </p>
              
            <button type = "button" onclick = "geeks()"
                Submit 
            </button
              
            <script
                function geeks() { 
                    document.getElementById("GFG").style.letterSpacing
                            = "8px"; 
                
            </script
        </center
    </body
</html>                    

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            DOM Style letterSpacing Property 
        </title
    </head
      
    <body
        <center
            <h1 style = "color:green;"
                GeeksForGeeks 
            </h1>
              
            <h2>
                DOM Style letterSpacing Property 
            </h2>
              
            <p id = "GFG">
                A computer science portal for geeks
            </p>
              
            <button type = "button" onclick = "geeks()"
                Submit 
            </button
              
            <script
                function geeks() { 
                    document.getElementById("GFG").style.letterSpacing
                            = "-1.5px"; 
                
            </script
        </center
    </body
</html>                    

chevron_right


Output:

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

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

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


My Personal Notes arrow_drop_up


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.