Javascript DOM CSS Style wordSpacing Property

Introduction

Set the space between words in a <p> element to 50 pixels:

document.getElementById("myP").style.wordSpacing = "50px";

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP">This is an example paragraph.</p>

<button type="button" onclick="myFunction()">Set word spacing</button>

<script>
function myFunction() {//www  .j av a  2 s .  c  o  m
  document.getElementById("myP").style.wordSpacing = "50px";
}
</script>

</body>
</html>

The wordSpacing property sets or gets the spacing between words in a text.

To set or return the spacing between characters in a text, use the letterSpacing property.

Property Values

Value Description
normal Defines normal spacing between words. default
length Sets the space between words in length units. Negative values are allowed
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The wordSpacing property return a String representing the space between words in the text.




PreviousNext

Related