Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / CSS

Proprietà CSS `letter-spacing`

`letter-spacing` aggiunge spaziatura tra i caratteri o usa la spaziatura normal del browser.

Versione: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Sintassi

normal | <length>

letter-spacing aggiunge spaziatura tra i caratteri o usa la spaziatura normal del browser.

L’esempio misura lo stesso testo di quattro caratteri prima e dopo 4px aggiuntivi.

Grammatica: normal | <length>.

Valori negativi possono sovrapporre i glifi; normal differisce da 0 nella giustificazione e non sostituisce il kerning.

Esempi

<!doctype html><html lang="en"><meta charset="utf-8"><title>CKTIS CSS example</title><body><pre id="result"></pre><script>const x=document.createElement("span");x.textContent="MMMM";document.body.prepend(x);x.style.cssText="display:inline-block;font:20px sans-serif;white-space:nowrap;letter-spacing:0";const a=Math.round(x.getBoundingClientRect().width);x.style.letterSpacing="4px";const b=Math.round(x.getBoundingClientRect().width);document.querySelector("#result").textContent="width="+a+"->"+b+"; computed="+getComputedStyle(x).letterSpacing;</script></body></html>

Risultato

width=67->83; computed=4px

L’esempio è stato eseguito localmente in una sessione Chrome isolata e senza rete; il risultato proviene dall’API CSS del browser.

Fonti