The non-breaking space ( ) is one of the most commonly used HTML entities. This guide explains what it is, when to use it, and how to avoid common mistakes.
Table of Contents
- What is ?
- When to Use Non-Breaking Spaces
- How to Insert
- vs Regular Space
- Best Practices and Alternatives
- Common Mistakes to Avoid
What is ?
stands for "non-breaking space" and is an HTML entity that creates a space that prevents automatic line breaks.
Key Characteristics:
- Creates a space character
- Prevents line wrapping at that position
- Takes up the same width as a regular space
- Can be used multiple times for wider spacing
HTML Entity Details:
| Property | Value |
|---|---|
| Entity name | |
| Entity number |   |
| Hexadecimal |   |
| Unicode | U+00A0 |
| Character | (non-breaking space) |
How It Works: When browsers encounter , they display a space but will NOT break the line at that position. This keeps adjacent words together on the same line.
Why Non-Breaking Spaces Exist
Regular spaces in HTML can be collapsed or used as line-break points. Non-breaking spaces solve two problems:
Problem 1: Space Collapsing
HTML collapses multiple spaces into one:
<!-- ❌ Multiple regular spaces collapse -->
<p>This has many spaces</p>
<!-- Output: "This has many spaces" (only single spaces) -->
<!-- ✅ Non-breaking spaces preserve spacing -->
<p>This has many spaces</p>
<!-- Output: "This has many spaces" (preserves spacing) -->
Problem 2: Unwanted Line Breaks
Browsers can break lines at regular spaces:
<!-- ❌ Regular space - can break awkwardly -->
<p>The price is 10 000 USD</p>
<!-- Could wrap to: "The price is 10
000 USD" -->
<!-- ✅ Non-breaking space - stays together -->
<p>The price is 10 000 USD</p>
<!-- Always: "The price is 10 000 USD" -->
When to Use Non-Breaking Spaces
1. Keeping Numbers Together
Prevent numbers and their units from separating:
<!-- Measurements -->
<p>The distance is 50 km</p>
<p>The temperature is 20 °C</p>
<p>The weight is 150 lbs</p>
<p>The height is 6 feet 2 inches</p>
<!-- Currencies -->
<p>Price: $100 USD</p>
<p>Cost: €50 EUR</p>
<p>Budget: £1,000 GBP</p>
<!-- Large numbers (European format) -->
<p>Population: 1 234 567</p>
<p>Revenue: $100 000 000</p>
2. Keeping Names Together
Prevent names from splitting across lines:
<!-- Personal names -->
<p>Dr. Jane Smith</p>
<p>Mr. John Doe</p>
<p>Prof. Mary Johnson</p>
<!-- Company names -->
<p>Apple Inc.</p>
<p>Google LLC</p>
<p>Microsoft Corporation</p>
<!-- Titles and chapters -->
<p>Chapter 5</p>
<p>Volume II</p>
<p>Section 3.4</p>
3. Dates and Times
Keep date components together:
<p>January 15, 2025</p>
<p>3 PM</p>
<p>10:30 AM</p>
<p>Q4 2024</p>
<p>Monday, Jan 15</p>
4. Abbreviations and Acronyms
Keep abbreviations with related text:
<p>i.e. for example</p>
<p>e.g. such as</p>
<p>etc. and so on</p>
<p>U.S. government</p>
<p>vs. (versus)</p>
5. Mathematical Expressions
Keep operators with operands:
<p>x + y = 10</p>
<p>5 × 3 = 15</p>
<p>a < b</p>
<p>10 / 2 = 5</p>
6. Initials and Academic Degrees
<p>J. K. Rowling</p>
<p>Ph. D.</p>
<p>M. A. in Psychology</p>
<p>B. Sc.</p>
How to Insert
Method 1: Entity Name (Most Common)
<p>Hello World</p>
Method 2: Entity Number
<p>Hello World</p>
Method 3: Hexadecimal
<p>Hello World</p>
Method 4: Direct Unicode (Not Recommended)
<p>Hello World</p>
<!-- Contains actual non-breaking space character - invisible in code -->
Avoid Direct Unicode: While you can type a non-breaking space directly (Alt+0160 on Windows, Option+Space on Mac), it's invisible in code and can cause confusion. Always use for clarity.
Multiple Non-Breaking Spaces
<!-- Two spaces -->
<p>Hello World</p>
<!-- Four spaces (em space equivalent) -->
<p>Hello World</p>
<!-- Creating aligned columns -->
<p>Name: John</p>
<p>Age: 25</p>
<p>City: London</p>
Using in JavaScript
// Create non-breaking space
const nbsp = '\\u00A0';
const nbsp2 = String.fromCharCode(160);
// Use in strings
const text = \`Hello\${nbsp}World\`;
document.body.innerHTML = text;
// Replace regular spaces with non-breaking spaces
const safeText = "10 000 USD".replace(/ /g, '\\u00A0');
console.log(safeText); // "10 000 USD" (won't break)
// Add to element
const element = document.querySelector('.price');
element.innerHTML = '50 km';
Using in CSS (with ::before or ::after)
/* Add non-breaking space before element */
.price::before {
content: '\\00A0';
}
/* Multiple non-breaking spaces */
.indent::before {
content: '\\00A0\\00A0\\00A0\\00A0';
}
/* Combination with text */
.label::after {
content: ':\\00A0';
}
vs Regular Space
| feature | regular Space | nbsp |
|---|---|---|
| Can wrap to new line | Yes | No |
| HTML collapses multiple | Yes | No |
| Width | Same | Same |
| Keyboard shortcut | Spacebar | Alt+0160 (Windows), Option+Space (Mac) |
| Semantic meaning | None | Keep together |
| Screen readers | Normal space | Normal space |
Visual Comparison
<!-- Regular space (can break): -->
<div style="width: 100px;">
This is a very long sentence that will wrap to
the next line when it runs out of space.
</div>
<!-- With (won't break at ): -->
<div style="width: 100px;">
This is a very long sentence that will
wrap but these words stay together.
</div>
Best Practices and Alternatives
When NOT to Use
1. For Layout/Spacing
<!-- ❌ Bad - Using for layout -->
<p>Left Right</p>
<!-- ✅ Good - Use CSS -->
<div style="display: flex; justify-content: space-between;">
<span>Left</span>
<span>Right</span>
</div>
<!-- Or -->
<div class="container">
<span class="left">Left</span>
<span class="right">Right</span>
</div>
<style>
.container { display: flex; justify-content: space-between; }
</style>
2. For Indentation
<!-- ❌ Bad - Using for indentation -->
<p> Indented paragraph</p>
<!-- ✅ Good - Use CSS -->
<p style="margin-left: 2em;">Indented paragraph</p>
<!-- Or -->
<p class="indented">Indented paragraph</p>
<style>
.indented { padding-left: 2em; }
</style>
3. For Vertical Spacing
<!-- ❌ Bad -->
<p>Line 1<br> <br>Line 2</p>
<!-- ✅ Good - Use CSS -->
<p style="margin-bottom: 1em;">Line 1</p>
<p>Line 2</p>
4. For Empty Table Cells
<!-- ❌ Bad -->
<td> </td>
<!-- ✅ Good - Leave empty or use CSS -->
<td></td>
<style>
td { min-width: 50px; min-height: 20px; }
</style>
Better Alternatives
CSS white-space Property
/* Prevent all line wrapping */
.no-wrap {
white-space: nowrap;
}
/* Preserve all spaces and line breaks */
.preserve {
white-space: pre;
}
/* Preserve spaces, allow wrapping */
.pre-wrap {
white-space: pre-wrap;
}
HTML <pre> Tag
<!-- For code or preformatted text -->
<pre>
This preserves all spacing
and line breaks automatically
</pre>
CSS Spacing Properties
/* Increase space between words */
.spaced {
word-spacing: 0.5em;
}
/* Increase space between letters */
.tracked {
letter-spacing: 0.1em;
}
/* Padding for spacing */
.box {
padding: 1em 2em;
}
/* Margin for spacing */
.section {
margin-bottom: 2em;
}
HTML5 <wbr> Tag
<!-- Suggests where line breaks CAN occur (opposite of ) -->
<p>supercali<wbr>fragilistic<wbr>expialidocious</p>
Common Use Cases with Examples
Financial Data
<table class="financial">
<tr>
<td>Revenue:</td>
<td>$1 234 567</td>
</tr>
<tr>
<td>Expenses:</td>
<td>$890 123</td>
</tr>
<tr>
<td>Profit:</td>
<td>$344 444</td>
</tr>
</table>
Product Specifications
<ul class="specs">
<li>Weight: 2.5 kg</li>
<li>Dimensions: 30 × 20 × 10 cm</li>
<li>Power: 100 W</li>
<li>Voltage: 220 V</li>
<li>Capacity: 500 GB</li>
</ul>
Addresses
<address>
123 Main Street<br>
Apartment 4B<br>
New York, NY 10001<br>
United States
</address>
Phone Numbers
<p>Call us: +1 (555) 123-4567</p>
<p>International: +44 20 1234 5678</p>
<p>Toll-free: 1-800 EXAMPLE</p>
Keyboard Shortcuts
<ul class="shortcuts">
<li>Save: Ctrl + S</li>
<li>Copy: Cmd + C</li>
<li>Paste: Cmd + V</li>
<li>Undo: Ctrl + Z</li>
<li>Find: Ctrl + F</li>
</ul>
Scientific Notation
<p>Speed of light: 3.0 × 10⁸ m/s</p>
<p>Avogadro's number: 6.022 × 10²³</p>
<p>Planck constant: 6.626 × 10⁻³⁴ J·s</p>
Common Mistakes to Avoid
1. Overusing for Layout
Don't do this: Using dozens of entities to create spacing is unmaintainable, inaccessible, and breaks responsive design.
<!-- ❌ Very bad -->
<p>Name: John</p>
<p>Email: john@example.com</p>
<!-- ✅ Good -->
<dl class="info-list">
<dt>Name:</dt>
<dd>John</dd>
<dt>Email:</dt>
<dd>john@example.com</dd>
</dl>
<style>
.info-list {
display: grid;
grid-template-columns: 100px 1fr;
gap: 0.5em;
}
</style>
2. Using Instead of Proper Markup
<!-- ❌ Bad -->
<p> • List item</p>
<p> • Another item</p>
<!-- ✅ Good -->
<ul>
<li>List item</li>
<li>Another item</li>
</ul>
3. Breaking SEO
<!-- ❌ Bad - Looks spammy to search engines -->
<h1>Best Product Ever</h1>
<!-- ✅ Good -->
<h1>Best Product Ever</h1>
4. Ignoring Locale-Specific Number Formatting
<!-- Different locales format numbers differently -->
<!-- US format -->
<p>1,000,000</p>
<!-- European format -->
<p>1 000 000</p>
<!-- German format -->
<p>1.000.000</p>
<!-- ✅ Best - Use JavaScript for locale-aware formatting -->
<script>
const num = 1000000;
document.write(num.toLocaleString()); // Formats based on user locale
</script>
5. Accessibility Issues
<!-- Screen readers pronounce as a space -->
<!-- For truly invisible spacing, use CSS or ARIA -->
<!-- ❌ Bad for accessibility -->
<button>Save Document</button>
<!-- ✅ Good -->
<button style="padding: 0.5em 2em;">Save Document</button>
Browser and Email Client Support
Browser Support
✅ Universal support:
- All modern browsers (Chrome, Firefox, Safari, Edge)
- Internet Explorer 5.5+
- Mobile browsers (iOS Safari, Chrome Mobile, Samsung Internet)
- Screen readers (announces as normal space)
Email Client Quirks
Email Limitations: Some email clients (especially older versions of Outlook) may strip or ignore entities. Test thoroughly or use CSS padding instead.
<!-- For emails, sometimes better to use: -->
<td style="padding-left: 20px;">Content</td>
<!-- Instead of: -->
<td> Content</td>
Quick Reference
Most Common Uses
<!-- Numbers with units -->
50 km
2.5 kg
100 W
20 °C
<!-- Currency -->
$100 USD
€50 EUR
<!-- Names -->
Dr. Smith
Mr. Jones
<!-- Dates -->
Jan 15, 2025
Q4 2024
<!-- Times -->
3 PM
10:30 AM
<!-- Math -->
x + y = 10
Alternative Entity Names
| Entity | Code | Description |
|---|---|---|
|   | Non-breaking space |
  |   | En space (half em) |
  |   | Em space (width of 'm') |
  |   | Thin space |
‌ | ‌ | Zero-width non-joiner |
‍ | ‍ | Zero-width joiner |
Summary
The non-breaking space ( ) is essential for keeping related words and numbers together on the same line. Use it for semantic meaning (things that should stay together), not for layout (use CSS instead).
Key Takeaways:
✅ creates a space that prevents line breaks
✅ Use for numbers with units, names, dates, and related text
✅ Don't use for layout, indentation, or spacing (use CSS)
✅ Can be used multiple times for wider spacing
✅ Supported in all browsers and screen readers
✅ Alternative notations:   or