Open In App

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:



object.style.letterSpacing
object.style.letterSpacing = "normal|length|initial|inherit"

Property Values:

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



Example 1: 




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

Output:

 

Example 2: 




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

Output:

 

 

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


Article Tags :