Special character for space
Learn the Unicode special space characters, how to identify which one is in your text, and how to replace or keep them without damaging meaningful content.
A search for a special character for space usually comes from one of two needs. You may want to type a space that behaves differently from the ordinary one, such as a space that never lets a line break between a number and its unit. Or you may have text where something looks like a space but does not act like one: a search fails, a split leaves two words stuck together, or a value refuses to match. Both problems have the same cause. Unicode defines many space characters, and most of them look almost identical on screen.
What inspecting space characters does for your text
A Unicode inspection takes any piece of plain text and reports each character's code point and official name. A code point is the unique number Unicode assigns to a character, written as U+ followed by hexadecimal digits, such as U+0020 for the ordinary space. Inspection makes it clear which space sits in each position. It does not change anything by itself. Text changes only when you apply a replacement or removal afterward. The scope here covers the visible space separators and the zero-width characters that are often mistaken for spaces or hidden inside words.
The space characters you are most likely to meet
| Character | Code point | HTML reference | Behavior | Typical use |
| Space | U+0020 | | Normal word space; a line may break here | Everyday text |
| No-break space | U+00A0 | | Similar width to a normal space; prevents a line break | Keeping "10 kg" or "p. 5" together |
| En space | U+2002 | | Half an em wide | Typesetting |
| Em space | U+2003 | | One em wide | Typesetting, fixed indents |
| Figure space | U+2007 | | Width of a digit; prevents a break | Aligning numbers in columns |
| Thin space | U+2009 | | Narrower than a normal space | Fine spacing around punctuation or digit groups |
| Hair space | U+200A | | Very narrow | Fine typographic adjustment |
| Narrow no-break space | U+202F | | Narrow; prevents a break | French punctuation spacing, digit grouping in some styles |
| Medium mathematical space | U+205F | | Medium width | Mathematical formulas |
| Ideographic space | U+3000 | | Width of a CJK character | Chinese, Japanese and Korean text |
| Zero width space | U+200B | | No visible width; allows a line break | Break opportunities in long unbroken strings |
| Word joiner | U+2060 | | No visible width; prevents a break | Gluing parts that must stay on one line |
| Zero width no-break space (byte order mark) | U+FEFF | | No visible width; at the start of a file it acts as a byte order mark | Often an accidental leftover from file encoding |
Actual widths depend on the font, so judge a character by its code point, not by how it looks. The characters fall into two groups. The visible spaces in the table belong to Unicode's space separator category (Zs) and carry the White_Space property. U+200B, U+2060 and U+FEFF are format characters (category Cf). Unicode does not classify them as whitespace, which is why trim, split and "collapse whitespace" functions often leave at least some of them in place.
How to tell which space you have, step by step
- 1. Copy the suspicious fragment exactly as it appears, including the characters around it. Do not retype it, because retyping replaces the original character with whatever your keyboard produces.
- 2. Make the characters visible. Use a code-point inspector, a short script like the ones below, or your editor's option to show invisible characters. Editors reliably distinguish ordinary spaces and tabs, but they may not mark every Unicode space differently, so confirm the code point itself.
- 3. Look up every code point other than U+0020 in the table above.
- 4. Decide, for each one, whether it is intentional. Keep it, replace it with an ordinary space, or remove it if it is a zero-width leftover.
- 5. Apply the change only to the characters you selected.
- 6. Verify the result using the checks described later in this guide.
Example: listing special spaces in Python
The following is an illustrative example. The sample string contains a no-break space between "Price:" and "100", a thin space before the euro sign, an ordinary space after it and a zero width space inside the word "check". The invisible characters are written as escape sequences so they stay explicit in the source.
import unicodedata
text = "Price:\u00a0100\u2009€ che\u200bck"
for i, ch in enumerate(text):
if ch != " " and (ch.isspace() or unicodedata.category(ch) in ("Zs", "Cf")):
name = unicodedata.name(ch, "<no name>")
print(f"{i:>3} U+{ord(ch):04X} {name}")
Based on the names defined in the Unicode character database, this script should report U+00A0 NO-BREAK SPACE, U+2009 THIN SPACE and U+200B ZERO WIDTH SPACE, each with its position in the string. The output was not run for this article. Including category Cf in the check means the script also reports other invisible format characters, such as zero width joiners, so you can review them instead of missing them.
Example: finding special spaces in JavaScript
const text = "Price:\u00A0100\u2009€ che\u200Bck";
const special = /[\u00A0\u1680\u2000-\u200B\u202F\u205F\u2060\u3000\uFEFF]/g;
for (const match of text.matchAll(special)) {
const cp = match[0].codePointAt(0).toString(16).toUpperCase().padStart(4, "0");
console.log(match.index, "U+" + cp);
}
This illustrative snippet lists each character explicitly instead of relying on \s. In JavaScript regular expressions, \s matches the Unicode space separators and U+FEFF, but it does not match U+200B or U+2060. An explicit character class catches all of them and leaves the ordinary space out of the results. U+1680 is the Ogham space mark, another space separator that is included for completeness.
Replacing special spaces without damaging the text
Converting every special space to U+0020 is the most common fix, but it is not always correct. Check these cases before you replace anything in bulk:
- No-break and narrow no-break spaces are often deliberate. They keep numbers with units, initials with surnames and French punctuation with the preceding word. Replacing them allows unwanted line breaks.
- The ideographic space has a layout role in CJK text and may be expected there.
- Figure spaces may be keeping numeric columns aligned.
- Removing zero-width spaces is usually safe, but do not widen that into stripping every invisible format character. U+200C (zero width non-joiner) and U+200D (zero width joiner) change how text renders in scripts such as Persian and in emoji sequences. Removing them alters meaningful content.
The illustrative function below replaces only the visible special spaces and removes only three zero-width characters. Edit both character classes to match the decisions you made during inspection. For example, remove \u00a0 from the first class if your no-break spaces are intentional.
import re
SPACES = re.compile("[\u00a0\u2000-\u200a\u202f\u205f\u3000]")
ZERO_WIDTH = re.compile("[\u200b\u2060\ufeff]")
def clean(text):
text = SPACES.sub(" ", text)
return ZERO_WIDTH.sub("", text)
Unicode normalization form NFKC also maps most visible special spaces, including U+00A0, U+2002, U+2003, U+2009, U+202F and U+3000, to an ordinary space. However, it does not remove U+200B, and it rewrites unrelated characters too, such as fullwidth letters, superscript digits and ligatures like "fi". Use it only when that broader change is acceptable.
Verifying the result
- Re-run the inspection on the cleaned text. No code points from the set you replaced should remain.
- Compare lengths. Replacing a special space with U+0020 leaves the length unchanged, and each removed zero-width character shortens it by one. Any other difference means something else was touched.
- Compare the original and cleaned text at the character level. A visual comparison will not show the difference between two kinds of space.
- Confirm that any no-break spaces you chose to keep are still present.
- If the text lives in a file, check how it is saved. An editor set to save as "UTF-8 with BOM" will write U+FEFF back at the start of the file.
Typing a special space on purpose
In HTML, use the references from the table, such as for a no-break space or for a narrow no-break space. In program source code, prefer escape sequences such as \u00A0 over pasting the literal character, so the character stays visible to anyone reading the code. In Microsoft Word, Ctrl+Shift+Space inserts a nonbreaking space. Many macOS keyboard layouts produce a no-break space with Option+Space, and on Windows, Alt+0160 on the numeric keypad inserts one in many applications. Shortcuts vary by application and keyboard layout, so confirm what you typed with the inspection step.
Limits of this guide
No evidence about specific inspection tools was available for this guide. It therefore does not compare named tools or make claims about how particular editors or fonts display each character. The code points, names, categories and normalization behavior described here come from the Unicode standard. The code samples are illustrative and were not executed for this article.