CSS word-spacing Property
The CSS word-spacing property controls the amount of additional space between words in text.
It can increase or decrease the spacing between words using length values such as pixels, ems, and rems. The property is useful for adjusting typography, improving text presentation, and creating specific visual effects without changing the spaces in the HTML content.
On This Page
Syntax
The word-spacing property accepts the keyword normal or a CSS length value.
selector {
word-spacing: normal | <length>;
}
Common declarations include:
p {
word-spacing: normal;
}
.spaced-text {
word-spacing: 5px;
}
.compact-text {
word-spacing: -2px;
}
.relative-text {
word-spacing: 0.2em;
}
Positive values increase spacing, while negative values reduce it. A value of 0 adds no extra spacing.
The property also accepts CSS-wide keywords such as inherit, initial, unset, revert, and revert-layer.
Property Values
| Value | Description |
|---|---|
normal |
Uses the browser's normal word spacing for the font. This is the initial value and allows spacing adjustments during text justification. |
<length> |
Specifies additional spacing between words using units such as px, em, rem, or ch. |
0 |
Adds no extra word spacing beyond the font's normal spacing. |
initial |
Resets the property to its initial value, normal. |
inherit |
Uses the computed word-spacing value of the parent element. |
unset |
Uses the inherited value because word-spacing is an inherited property. |
revert |
Reverts the property according to the CSS cascade. |
revert-layer |
Reverts the property according to the previous cascade layer. |
Percentage values are not supported by the word-spacing property. Use a supported length unit instead.
How It Works
Browsers normally determine the width of spaces between words using the selected font. The word-spacing property adjusts that spacing without modifying the text itself.
For example, the following declaration adds 6 pixels of space at word-separation opportunities:
.paragraph {
word-spacing: 6px;
}
If the font normally displays a space at approximately 4 pixels, adding 6 pixels produces a larger visible gap. The actual result depends on the font and browser.
The property affects word-separation opportunities rather than inserting literal spaces into the HTML. It does not change the text's characters or add new words.
Because spacing changes the width of text, it can also influence where lines wrap inside a container.
Positive Word Spacing
Positive values increase the distance between words. This can create a more open appearance in headings, labels, and short text.
.heading {
word-spacing: 8px;
}
The browser adds the specified amount to the normal word spacing.
For example:
.small-spacing {
word-spacing: 2px;
}
.medium-spacing {
word-spacing: 5px;
}
.large-spacing {
word-spacing: 10px;
}
Larger values create more separation, but excessive spacing can make sentences difficult to read because related words appear disconnected.
Use moderate values when adjusting body text and test the result at different screen sizes.
Negative Word Spacing
Negative values reduce the normal distance between words.
.compact-text {
word-spacing: -2px;
}
This can create a tighter appearance, particularly in short headings or decorative text.
However, negative spacing can cause words to appear too close together or overlap when the reduction exceeds the available spacing.
.very-compact {
word-spacing: -6px;
}
Large negative values are generally unsuitable for paragraphs because they can make individual words difficult to distinguish.
Negative values are valid CSS, but they should be used carefully and checked with the actual font and content.
Relative Units
The word-spacing property supports relative length units, allowing spacing to scale with text or other sizing settings.
Using em
The em unit is relative to the font size of the element.
.relative-spacing {
font-size: 20px;
word-spacing: 0.25em;
}
In this example, 0.25em corresponds to 5 pixels of additional spacing because the font size is 20 pixels.
Using rem
The rem unit is relative to the root element's font size.
.root-spacing {
word-spacing: 0.3rem;
}
If the root font size is 16 pixels, the additional spacing is 4.8 pixels.
Using ch
The ch unit is based on the advance measure of the 0 character in the selected font.
.character-spacing {
word-spacing: 0.5ch;
}
This can be useful when spacing should relate to the font's character measurements rather than a fixed pixel value.
Choosing a Unit
Use px for fixed adjustments and em when the spacing should scale with the element's font size. The rem unit is useful when spacing should remain relative to the root font size.
word-spacing vs. letter-spacing
The word-spacing and letter-spacing properties both control text spacing, but they affect different parts of the text.
| Property | Purpose |
|---|---|
word-spacing |
Adjusts spacing at word-separation opportunities. |
letter-spacing |
Adjusts the spacing between typographic character units. |
For example:
.text-example {
word-spacing: 6px;
letter-spacing: 1px;
}
This declaration increases both the spacing between words and the spacing between letters.
The properties can be combined, but excessive spacing may reduce readability. For most body text, the font's default spacing is a suitable starting point.
Examples
Example 1: Normal Word Spacing
The normal value uses the browser's standard spacing behavior.
.normal-text {
word-spacing: normal;
}
This is the default and is appropriate for most paragraphs.
Example 2: Increasing Word Spacing
A positive length value increases the spacing between words.
.wide-text {
word-spacing: 7px;
}
This can create a more open appearance in short text.
Example 3: Reducing Word Spacing
A negative length value reduces the normal spacing.
.tight-text {
word-spacing: -1px;
}
Small negative adjustments can produce a more compact appearance without substantially affecting readability.
Example 4: Responsive Word Spacing
Media queries can adjust word spacing for different screen widths.
.responsive-heading {
word-spacing: 0.3em;
}
@media (max-width: 600px) {
.responsive-heading {
word-spacing: normal;
}
}
This example uses additional spacing on wider screens and returns to normal spacing on narrower screens.
Example 5: Combining Word and Letter Spacing
Both properties can be used together for decorative headings.
.display-heading {
word-spacing: 0.4em;
letter-spacing: 0.05em;
}
The result increases spacing between words while adding a smaller amount of spacing between letters.
Example 6: Resetting Word Spacing
Use normal to restore standard spacing.
.custom-text {
word-spacing: 5px;
}
.custom-text.reset {
word-spacing: normal;
}
The second rule restores the browser's normal word-spacing behavior when the reset class is present.
Inheritance
The word-spacing property is inherited. Child elements normally receive the computed word-spacing value of their parent unless another value is specified.
.parent {
word-spacing: 4px;
}
.child {
/* Inherits 4px */
}
For example, applying word-spacing to a paragraph also affects text inside nested elements such as <strong> and <em>.
The initial value is normal. Length values are computed to absolute lengths, so inherited relative spacing does not automatically recalculate against a child's different font size.
To make spacing relative to each child's font size, specify an appropriate em value directly on those elements.
Practical Example
This example compares normal, increased, and reduced word spacing using the same sentence.
HTML
<div class="word-spacing-demo">
<div class="word-spacing-example">
<strong>word-spacing: normal</strong>
<p class="word-spacing-normal">
CSS controls the spacing between words.
</p>
</div>
<div class="word-spacing-example">
<strong>word-spacing: 8px</strong>
<p class="word-spacing-wide">
CSS controls the spacing between words.
</p>
</div>
<div class="word-spacing-example">
<strong>word-spacing: -2px</strong>
<p class="word-spacing-tight">
CSS controls the spacing between words.
</p>
</div>
</div>
CSS
.word-spacing-demo {
display: grid;
gap: 12px;
}
.word-spacing-example {
padding: 12px;
border: 1px solid #ccc;
background: #f5f5f5;
}
.word-spacing-example strong {
display: block;
margin-bottom: 8px;
}
.word-spacing-example p {
margin: 0;
line-height: 1.6;
}
.word-spacing-normal {
word-spacing: normal;
}
.word-spacing-wide {
word-spacing: 8px;
}
.word-spacing-tight {
word-spacing: -2px;
}
CSS controls the spacing between words.
CSS controls the spacing between words.
CSS controls the spacing between words.
Result: The first example uses normal word spacing. The second adds 8 pixels between words, creating a more open appearance. The third reduces the spacing by 2 pixels, producing tighter text.
The examples demonstrate how word-spacing changes the visual distance between words without modifying the HTML text.
Common Mistakes
Using Percentage Values
The word-spacing property does not accept percentages.
/* Incorrect */
.text {
word-spacing: 20%;
}
/* Correct */
.text {
word-spacing: 0.2em;
}
Use a valid CSS length value instead.
Confusing Word Spacing with Letter Spacing
The word-spacing property does not adjust the spacing between every letter. Use letter-spacing for character spacing.
Using Excessive Negative Values
Large negative values can make words overlap or appear joined together.
/* May reduce readability */
.text {
word-spacing: -10px;
}
Use small adjustments and test the result with the selected font.
Applying Large Values to Body Text
Excessive word spacing can make paragraphs difficult to follow and increase unwanted line wrapping.
Reserve larger values for short decorative text when appropriate.
Expecting Word Spacing to Add HTML Spaces
The property changes the visual spacing between words. It does not insert space characters or modify the underlying text.
Ignoring Inheritance
Because word-spacing is inherited, a declaration on a parent can affect all descendant text.
Apply the property to the intended text elements rather than broad containers when different spacing is required.
Important Considerations
- Readability: Moderate word spacing helps maintain clear visual relationships between words.
- Font differences: The visible result depends on the font's normal spacing characteristics.
- Relative units: Use
emwhen spacing should scale with the element's font size. - Responsive layouts: Additional spacing may cause text to wrap earlier in narrow containers.
- Accessibility: Avoid unnecessarily restricting user-adjusted text spacing through fixed heights or hidden overflow.
- Inheritance: Child elements inherit the computed value unless they specify their own spacing.
- Justified text: Browsers may adjust spacing further when
text-align: justifyis used. - Writing systems: The effect of word spacing can vary with language and writing system because not all languages separate words with spaces.
- Animation: Length values can be animated or transitioned, although changing text spacing may trigger layout recalculations.
For most paragraphs, word-spacing: normal provides suitable spacing. Custom values are best used when there is a specific typography requirement.
Browser Support
The CSS word-spacing property is widely supported in modern browsers, including Chrome, Edge, Firefox, Safari, and Opera.
The normal keyword and positive or negative length values have long-standing browser support. The exact appearance may vary slightly depending on the font, language, and browser's text-rendering behavior.
For current compatibility information, visit Can I Use? .
Specifications
The word-spacing property is defined in the CSS Text Module Level 3 specification, which describes spacing and line layout for text.
