Style letterSpacing Property

Definition and Usage

letterSpacing Property to set or return the spacing between characters in the text (character spacing).

Tip:To set or return the spacing between words in the text (word spacing), use wordSpacing property.

See also:

CSS Tutorial:CSS Text

CSS Reference Manual:letter-spacing property

Instance

Example 1

Sets the spacing between characters in the <p> element to 15 pixels:

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

Try It Yourself

Example 2

Use negative values:

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

Try It Yourself

Example 3

Returns the letter spacing of the <p> element:

alert(document.getElementById("myP").style.letterSpacing);

Try It Yourself

Example 4

Difference between letterSpacing property and wordSpacing property:

function changeLetters() {
  document.getElementById("myP1").style.letterSpacing = "15px";
}
function changeWords() {
  document.getElementById("myP2").style.wordSpacing = "15px";
}

Try It Yourself

Syntax

Return letterSpacing property:

object.style.letterSpacing

Set letterSpacing property:

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

Property Value

Value Description
normal Normal spacing between characters. Default.
length Defined by length units. Allows negative values.
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical Details

Default value: normal
Return value: A string that represents the spacing between characters in the text.
CSS Version: CSS1

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support