Style letterSpacing attribute

Definition and Usage

letterSpacing Sets or returns 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 κείμενο

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"

Attribute 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 representing the spacing between characters in the text.
CSS Version: CSS1

Υποστήριξη Browser

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη