What Is NBSP? Non-Breaking Space in HTML and Markdown
November 11, 2026 · 10 min read
What Is NBSP? The Non-Breaking Space and Other Whitespace Characters
NBSP stands for non-breaking space, the Unicode character U+00A0 that HTML writes as . It looks exactly like a normal space but behaves differently in two ways: a line never wraps at it, and HTML never collapses it. Use it to keep a number and its unit, or a title and a name, on the same line.
What Does NBSP Mean?
A non-breaking space is a space with one job: it glues the words on either side together. Unicode calls it U+00A0 NO-BREAK SPACE and files it under the space separator category (Zs). In UTF-8 it takes two bytes, C2 A0, while an ordinary space is the single byte 20.
In HTML you'll usually meet it as the named entity . An entity is a short text code that the browser swaps for a character while it parses the page. The WHATWG list of named character references maps to code point 160, and the longer   points to the same character.
So the short meaning of is "a space that sticks". It has two properties an ordinary space lacks:
- No line break. Text never wraps at that position, so the words on both sides stay on one line.
- No collapsing. Five of them in a row still show as five spaces in a browser.
How HTML Handles Whitespace Characters
HTML source is full of whitespace nobody sees: indentation, newlines between tags, double spaces after a period. CSS decides what happens to it. So what are whitespace characters, as far as the browser is concerned? The CSS Text Module Level 3 defines the document white space characters as just three kinds: spaces (U+0020), tabs (U+0009) and segment breaks such as line feeds.
Under the default white-space: normal, those whitespace characters are collapsible. A run of spaces, tabs and newlines between two words shrinks to one space, and spaces at the start or end of a line disappear. U+00A0 isn't in that set, so the browser leaves every one of them alone.
<p>Normal: three spaces collapse.</p>
<p>Kept: three spaces.</p>
The first paragraph renders as "Normal: three spaces collapse." with single gaps. The second keeps three character widths between each word, and the browser can't wrap anywhere inside it.
If you want a whole block to keep its spacing, entities are the wrong tool. Set white-space: pre-wrap on the element to keep spaces and newlines while still wrapping long lines, or use a <pre> element for code and ASCII art. Tabs kept this way jump to stops every 8 columns by default, as our guide to how many spaces in a tab explains.
Why Do We Use NBSP in HTML?
The main reason is to stop a line break in the wrong place. A browser may wrap at any ordinary space, which can strand a number on one line and its unit on the next. These are the cases where a non-breaking space earns its place:
- Numbers with units:
10 km,250 ms,16 GB - Times and dates:
9:30 am,March 14 - Titles and initials:
Dr. Smith,J. Doe - References:
page 3,Figure 2,Chapter IV - French punctuation: French typesetting puts a non-breaking space before a colon, question mark or exclamation mark, so the mark never starts a line on its own.
Some writers also glue the last two words of a headline so a single word doesn't sit alone on the final line.
We prefer to use only for these glue jobs. Anything that's really layout, such as gaps, indents or alignment, belongs in CSS, where it adapts to the font and the screen width.
How Do I Enter a Space in HTML?
A plain space works for a single gap between words. For a non-breaking one you have several spellings, and every row below produces the same U+00A0 character.
| Context | How to write it | Notes |
|---|---|---|
| HTML named entity | | The most readable form |
| HTML decimal reference |   | Also works in plain XML, which predefines only five entities |
| HTML hex reference |   | Same character, hexadecimal code |
| Raw character | U+00A0, typed or pasted | Invisible in most editors |
| CSS generated content | content: "\00a0"; | Inside a ::before or ::after rule |
| JavaScript string | "\u00A0" | String.fromCharCode(160) gives the same result |
Browsers also accept   without the semicolon, because it's on the spec's list of legacy entities. The HTML parser still flags it as an error, so always type the semicolon. If you need the literal text on screen, escape the ampersand as &nbsp;.
Three related entities give fixed-width gaps:   and   are wider and   is narrower. Unlike , lines can still wrap at all three. Our table of Unicode space characters lists the width and code point of each one.
Typing a Non-Breaking Space in Word, Google Docs, Mac and Windows
Outside code, you don't type an entity. You type the character itself. The shortcut depends on the app and the system:
- Word for Windows: Ctrl+Shift+Space, per Microsoft's Word keyboard shortcuts page. Turn on Show/Hide ¶ and it appears as a small raised circle instead of a dot.
- Word for Mac: Option+Space, listed on the same Microsoft page.
- Other Mac apps: on the standard US layout, Option+Space types U+00A0 in most apps. That's also how many accidental ones appear, when you're still holding Option after typing a symbol.
- Other Windows apps: hold Alt and type 0160 on the numeric keypad with Num Lock on. The number row doesn't work, so on a laptop without a keypad use the Character Map app, which lists it as No-Break Space.
- Google Docs: open Special characters from the Insert menu and look up the no-break space in the dialog's search box.
In HTML, Markdown or any file under version control, type instead of the raw character. A reviewer can see an entity in a diff, but a raw U+00A0 looks like any other space.
When to Skip the Non-Breaking Space
Chains of used for layout cause more trouble than they solve. They depend on the font size, they don't adapt to screen width, and the next person to edit the page can't tell what they're for. CSS covers each of those jobs directly:
<span style="white-space: nowrap">Keep this phrase together</span>
<p style="text-indent: 2em">A first-line indent without entities.</p>
<td style="padding-left: 1rem">Spacing inside a table cell</td>
The nowrap value keeps a whole phrase on one line without touching its spaces. Use margin or padding for gaps between elements, text-indent for paragraph indents, and a table or grid for alignment. If you're indenting inside Markdown, our Markdown indentation guide covers the options.
There's one real limitation to keep in mind. A glued run is a single unbreakable unit, so a long chain of words joined by non-breaking spaces can't wrap on a narrow phone screen. It overflows its container or forces sideways scrolling, so keep each glued run to two or three short words.
Finding Invisible NBSP Characters in Pasted Text
Stray non-breaking spaces are a classic bug because they look identical to normal spaces. They arrive in text copied from Word documents, web pages, PDFs and chat apps. Watch for these symptoms:
- An
Âbefore spaces. The UTF-8 bytesC2 A0were read as Windows-1252 or Latin-1, whereC2displays asÂ. Fix the declared encoding (for example<meta charset="utf-8">) instead of deleting the letter. - Comparisons that should match but don't. In JavaScript,
"10\u00A0km" === "10 km"is false. - Searches that miss. Searching for
10 kmwon't find10andkmjoined by U+00A0. - Code that won't run. Recent Python 3 versions stop with
SyntaxError: invalid non-printable character U+00A0when one lands in source code.
The behaviour isn't consistent, which makes the bug harder to spot. JavaScript's trim() and the regex \s both treat U+00A0 as whitespace, and Python's str.split() with no argument splits on it too. So trimming can look fine while an exact comparison still fails. In Python, text.replace("\u00a0", " ") swaps them for ordinary spaces.
To find and fix them in JavaScript:
const s = "10\u00A0km";
s === "10 km"; // false
/\u00A0/.test(s); // true, it contains an NBSP
encodeURIComponent(s); // "10%C2%A0km" makes it visible
s.replace(/\u00A0/g, " ") === "10 km"; // true after the replace
On the command line, grep -n $'\xC2\xA0' notes.md prints every line in a UTF-8 file that contains one (bash and zsh understand that quoting).
Using NBSP in Markdown
Markdown passes entities straight through. The CommonMark spec treats ,   and   as the character they stand for, except inside code spans and code blocks, where they stay literal text. Three consequences follow.
First, an entity in prose becomes a real non-breaking space in the HTML, so 10 km stays on one line. Second, raw NBSPs don't count as structural whitespace. Four of them at the start of a line don't create an indented code block. Two at the end of a line don't create a hard break either, because CommonMark wants two ordinary spaces or a backslash there. Our Markdown line break guide covers those options.
Third, emphasis can fail. CommonMark counts U+00A0 as Unicode whitespace, so **bold ** with a pasted NBSP before the closing asterisks renders as literal asterisks, just as an ordinary space would.
The trip is 10 km long.
Show the entity itself: \ or ` `
The first line renders as "The trip is 10 km long." with a space that won't wrap. The second shows the text twice, once through a backslash escape and once inside a code span. Our guide to escaping Markdown characters explains both methods.
Edit the sample below and watch the preview keep the entities while the plain spaces collapse:
The Markdown to HTML converter runs in your browser and turns the same text into a full HTML document, so you can check that each entity made it through. One caveat for line breaks: our editor renders every single newline as a line break, GitHub-comment style. Test the trailing-NBSP case on a strict CommonMark renderer instead.
An NBSP is a small character with a narrow job: keep words together and survive HTML's whitespace collapsing. Use the entity for units, times, names and references, reach for CSS when the real goal is layout, and check pasted text whenever a comparison fails for no visible reason. To see how entities and plain spaces behave side by side, paste your text into the editor and watch the live preview.