Table of contents
1.
Introduction
2.
Definition and Usage
3.
CSS Syntax
4.
Formal Syntax  
5.
Example
6.
Property Values
7.
Examples
7.1.
Example 1: Increasing Letter Spacing for Headings
7.2.
Example 2: Compacting Text
7.3.
Example 3: Using Em Units
8.
Accessibility  
9.
Internationalization Concerns  
10.
Browser Support
11.
Frequently Asked Questions
11.1.
What does letter-spacing: normal do? 
11.2.
Can I use negative values in letter-spacing? 
11.3.
What units can I use for letter-spacing? 
12.
Conclusion
Last Updated: Jan 11, 2025
Easy

CSS letter-spacing property

Author Sinki Kumari
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

CSS (Cascading Style Sheets) is a powerful tool for styling and designing web pages. One such property is letter-spacing, which controls the space between the characters in text. 

CSS letter-spacing property

This article will discuss how to use the letter-spacing property effectively to improve text readability and style. 

Definition and Usage

The CSS `letter-spacing` property is used to control the space between characters in a text. It can be applied to any text element, such as paragraphs, headings, or spans. The property accepts values in various units, including pixels (`px`), ems (`em`), or percentages (`%`). Positive values increase the space between characters, while negative values decrease it.  

By adjusting the letter spacing, you can make your text more readable or achieve specific design effects.

For example, increasing the letter spacing is common in headlines to make them stand out, while decreasing it can fit text into tighter spaces.

CSS Syntax

The syntax for the letter-spacing property is simple. Here is the general structure:

selector {
  letter-spacing: value;
}

 

  • selector: The HTML element you want to apply the property to.
     
  • value: Can be a length value (e.g., px, em, %), normal, or a negative value.

Formal Syntax  

The formal syntax of the CSS `letter-spacing` property is straightforward but powerful. It allows you to define the spacing between characters in a precise & flexible way. The syntax is :  

letter-spacing: normal | <length> | inherit;


In this syntax:  

1. `normal`: This is the default value. It means the browser will use the default spacing defined by the font & the text rendering engine. No additional spacing is added or removed.  
 

2. `<length>`: This specifies the amount of space to add or remove between characters. It can be a positive value (to increase spacing), a negative value (to decrease spacing), or zero (to reset spacing). The value can be in units like `px`, `em`, `rem`, or `%`.  
 

3. `inherit`: This makes the element inherit the `letter-spacing` value from its parent element.  


Let’s understand this with a complete code example:  

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Letter Spacing Syntax Example</title>
  <style>
    /* Default spacing */
    p.default {
      letter-spacing: normal;
    }

    /* Positive length value */
    p.positive {
      letter-spacing: 3px;
    }

    /* Negative length value */
    p.negative {
      letter-spacing: -1px;
    }

    /* Inherit value */
    div {
      letter-spacing: 2px;
    }
    p.inherit {
      letter-spacing: inherit;
    }
  </style>
</head>
<body>
  <p class="default">This is text with normal letter spacing.</p>
  <p class="positive">This is text with 3px letter spacing.</p>
  <p class="negative">This is text with -1px letter spacing.</p>
  <div>
    <p class="inherit">This text inherits 2px letter spacing from its parent.</p>
  </div>
</body>
</html>

 

Output

Output

In this example:  

  • The first paragraph uses `normal` letter spacing, which is the default.  
     
  • The second paragraph applies a positive value (`3px`), increasing the space between characters.  
     
  • The third paragraph uses a negative value (`-1px`), reducing the space between characters.  
     
  • The fourth paragraph demonstrates the `inherit` value, where the child element (`<p>`) inherits the `letter-spacing` value (`2px`) from its parent (`<div>`).  


This example shows how the formal syntax of `letter-spacing` can be applied in real-world scenarios.  

Example

h1 {
  letter-spacing: 2px; /* Adds 2px spacing between letters */
}


p {
  letter-spacing: -1px; /* Reduces spacing by 1px */
}


span {
  letter-spacing: normal; /* Resets to default spacing */
}

Property Values

The letter-spacing property supports the following values:

1. normal: Sets the default letter spacing for the font.
Example:

p {
  letter-spacing: normal;
}


Output: The text appears with the default spacing for the applied font.


2. Positive Values: Increase the space between characters.
Example:

h1 {
  letter-spacing: 3px;
}


Output: Each character in the text has an additional 3 pixels of spacing.

3. Negative Values: Decrease the space between characters.
Example:

.compact {
  letter-spacing: -2px;
}


Output: Characters are closer together by 2 pixels.


4. Length Values: Use units like px, em, %, etc.
Example:

p {
  letter-spacing: 0.1em;
}


Output: Spacing adjusts based on the font size (1em = font size).

Examples

Here are some practical examples to demonstrate the use of the letter-spacing property.

Example 1: Increasing Letter Spacing for Headings

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Letter Spacing Example</title>
  <style>
    h1 {
      letter-spacing: 5px;
    }
  </style>
</head>
<body>
  <h1>Welcome</h1>
</body>
</html>


Output: 

Output


The heading "Welcome" will have 5px of space between each character, making it more spaced out.

Example 2: Compacting Text

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Compact Text</title>
  <style>
    p {
      letter-spacing: -1px;
    }
  </style>
</head>
<body>
  <p>This is compact text.</p>
</body>
</html>


Output: 

 

Output


The text "This is compact text." will have characters closer together by 1 pixel.

Example 3: Using Em Units

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Em Letter Spacing</title>
  <style>
    span {
      letter-spacing: 0.2em;
    }
  </style>
</head>
<body>
  <span>Stylish Text</span>
</body>
</html>


Output: 

Output

The text "Stylish Text" will have spacing equivalent to 20% of the font size.

Accessibility  

When working with CSS letter spacing, accessibility is a critical factor to consider. Proper spacing between letters can significantly improve readability, especially for users with visual impairments or reading difficulties like dyslexia. However, overusing or misusing this property can have the opposite effect, making text harder to read.  

For example, increasing letter spacing too much can cause words to break apart, making it difficult for users to recognize them as a single unit. On the other hand, reducing letter spacing too much can make text look cramped & illegible. The key is to strike a balance that enhances readability without compromising the user experience.  

Let’s take an example of how to use letter spacing effectively:  

/* Good practice: Moderate letter spacing for better readability */
p {
  letter-spacing: 1.5px;
}

/* Bad practice: Excessive letter spacing */
h1 {
  letter-spacing: 10px; /* This can make text hard to read */
}


Moreover, when designing for accessibility, always test your text with screen readers & ensure that the spacing adjustments do not interfere with the way text is read aloud. Tools like browser developer tools & accessibility checkers can help you evaluate the impact of your letter spacing choices.  

Internationalization Concerns  

When working with CSS letter spacing, it’s important to consider internationalization (i18n). Different languages & scripts have unique typographic requirements, & what works for English might not work for other languages. For instance, some scripts, like Arabic or Chinese, rely on specific character spacing rules that should not be altered. Applying uniform letter spacing across all languages can lead to readability issues or even break the text layout.  

For example, in Arabic, letters are often connected, & adding extra spacing can disrupt the natural flow of the script. Similarly, in languages like Japanese or Chinese, characters are designed to fit together tightly, & excessive spacing can make the text look awkward or disjointed.  

Let’s take a look at an example of how to handle letter spacing for multilingual content:  

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Letter Spacing Example</title>
  <style>
    /* Default letter spacing for English */
    p {
      letter-spacing: 1px;
    }
    /* No letter spacing for Arabic */
    [lang="ar"] {
      letter-spacing: 0;
    }


    /* Moderate letter spacing for Japanese */
    [lang="ja"] {
      letter-spacing: 0.5px;
    }
  </style>
</head>
<body>
  <p lang="en">This is an example of English text with letter spacing.</p>
  <p lang="ar">هذا مثال لنص عربي بدون تباعد بين الأحرف.</p>
  <p lang="ja">これは日本語のテキストの例です。</p>
</body>
</html>


Output

Output

In this example, the `lang` attribute is used to apply different letter spacing rules based on the language. This ensures that the text remains readable & visually appropriate for each language.  

Browser Support

The letter-spacing property is supported by all major browsers, making it a reliable choice for web development. Below is a table showing its compatibility:

BrowserSupported Versions
Google ChromeAll versions
Mozilla FirefoxAll versions
Microsoft EdgeAll versions
SafariAll versions
OperaAll versions

You can use this property without worrying about compatibility issues.

Frequently Asked Questions

What does letter-spacing: normal do? 

It sets the letter spacing to the default value for the font.

Can I use negative values in letter-spacing? 

Yes, negative values decrease the space between characters, making them closer.

What units can I use for letter-spacing? 

You can use length units like px, em, %, and more. Choose based on your design needs.

Conclusion

The letter-spacing property in CSS is a simple yet powerful way to control the spacing between characters in text. It enhances readability, creates unique designs, and ensures text fits well in various layouts. By understanding and using this property effectively, you can significantly improve your web designs and make them stand out.

You can also check out our other blogs on Code360.

Live masterclass