HTML - DOM Style Object wordSpacing Property



HTML DOM Style Object wordSpacing property sets or returns spacing between words of the sentences.

Syntax

Set the wordSpacing property:
object.style.wordSpacing= "normal | length | initial | inherit";
Get the wordSpacing property:
object.style.wordSpacing;

Property Values

Value Description
normal It is the default value which specifies the normal spacing between the words.
length It sets the space between words in length units.It accepts negative values.
initial It is used to set this property to it's default value.
inherit It is used to inherit the property of it's parent element.

Return Value

It returns a string value which represents the space between the words in a text.

Examples of HTML DOM Style Object 'wordSpacing' Property

The following examples sets the wordSpacing property for a div and span element.

Set wordSpacing for div Element

The following example sets the wordSpacing property for a div element to 100px.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object wordSpacing Property
    </title>
</head>
<body>
    <p>
        Click to set wordSpacing property.
    </p>
    <button onclick="fun()">Set wordSpacing</button>
    <br><br>
    <div id="space">
        Welcome to Tuorials Point
    </div>
    <script>
        function fun() {
            document.getElementById("space")
                .style.wordSpacing = "100px";
        }
    </script>
</body>
</html>

Set wordSpacing for span Element

The following example sets the wordSpacing property for a span element to 100px.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object wordSpacing Property
    </title>
</head>
<body>
    <p>
        Click to set wordSpacing property.
    </p>
    <button onclick="fun()">
        Set wordSpacing
    </button>
    <br><br>
    <span id="space">
        Welcome to Tuorials Point
    </span>
    <script>
        function fun() {
            document.getElementById("space")
                .style.wordSpacing = "100px";
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
wordSpacing Yes 1 Yes 12 Yes 1 Yes 1 Yes 3.5
html_dom.htm
Advertisements