Javascript DOM CSS Style letterSpacing Property

Introduction

Set the space between characters in a <p> element to 15 pixels:

document.getElementById("myP").style.letterSpacing = "15px";

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {//from   www  . ja v  a2s .  co m
  document.getElementById("myP").style.letterSpacing = "15px";
}
</script>

</body>
</html>

The letterSpacing property sets or gets the space between characters in a text.

To set or return the spacing between words in a text, use the wordSpacing property.

Property Values

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

The letterSpacing property returns a String representing the space between characters in the text.




PreviousNext

Related