Home / Guides

Whitespace Characters: List, Escape Codes and Removal

Published 2026-11-06

Whitespace characters are the characters that separate words and lines without drawing a symbol. The ordinary space, the tab and the line break are the familiar ones, but Unicode defines many more, and different programs disagree about which count. This is a quick reference for writers and programmers. It lists the whitespace characters with their codes and escape sequences, shows what common tools treat as white space, and explains how to remove each kind.

Whitespace characters at a glance

The characters below are visible placeholders: they take up room, and you can see the gap they leave.

CharacterCodeEscapeUse
SpaceU+0020" "The everyday word separator
Horizontal tabU+0009\tIndentation and columns
Line feedU+000A\nLine break on Mac, Linux and the web
Carriage returnU+000D\rWindows uses \r\n; see carriage return
Vertical tabU+000B\vRare
Form feedU+000C\fPage break in old text files
No-break spaceU+00A0\u00a0A space that will not wrap
En space and em spaceU+2002, U+2003\u2002, \u2003Typesetting widths
Thin spaceU+2009\u2009Between a number and a unit, in some styles
Figure spaceU+2007\u2007As wide as a digit, to line up numbers
Narrow no-break spaceU+202F\u202fUsed in French and other typography
Ideographic spaceU+3000\u3000Full-width space in Chinese, Japanese and Korean text

The full set of spaces between U+2000 and U+200A is in our guide to Unicode space characters.

Whitespace that moves the text to a new line

CharacterCodeNotes
Line feedU+000AThe standard line ending on Unix, Mac and the web
Carriage returnU+000DOld Mac line ending; half of the Windows ending
Next lineU+0085A control code used as a line break in some old systems
Line separatorU+2028A Unicode line break inside a paragraph
Paragraph separatorU+2029A Unicode paragraph break

The difference between the Windows and Unix endings is covered in CRLF vs LF.

Invisible characters that are not whitespace

These look empty, but no whitespace check recognizes them.

CharacterCodeWhy it is not whitespace
Zero-width spaceU+200BA format character with no width
Word joinerU+2060A format character
Hangul fillerU+3164A letter
Braille pattern blankU+2800A symbol

See the guide to the blank character for how these behave.

What common tools treat as whitespace

Each language has its own definition. These results come from running the characters through the tools.

CharacterJavaScript \s and trim()Python str.isspace() and split()
Space, tab, line feed, carriage return, form feed, vertical tabYesYes
No-break space U+00A0YesYes
U+2000 to U+200A, U+202F, U+205F, U+3000YesYes
Line and paragraph separators U+2028, U+2029YesYes
Next line U+0085NoYes
Byte order mark U+FEFFYesNo
U+001C to U+001FNoYes
Zero-width space, Hangul filler, braille blankNoNo

Two practical lessons follow. First, never assume that a trim works the same way in two languages. Second, a trim in any of them leaves the zero-width space and the blank letters in place. Other tools are narrower still: Excel's TRIM function only deals with the ordinary space, character 32, and does not remove a no-break space. To fix that cell, replace character 160 first: =TRIM(SUBSTITUTE(A1, CHAR(160), " ")).

Escape sequences

Most programming languages write the common whitespace characters as backslash escapes inside strings.

How to remove whitespace

Collapse repeated whitespace

# Python: handles tabs, newlines and special spaces
text = " ".join(text.split())

// JavaScript
text = text.replace(/\s+/g, " ").trim();

Both flatten line breaks into spaces. If you want to keep paragraphs, work line by line.

Remove all whitespace

# Python
text = "".join(text.split())

// JavaScript
text = text.replace(/\s+/g, "");

With the AI Text Cleaner

The cleaner does not act as a remove-all-whitespace tool. It does these things instead:

Two behaviors are worth knowing. It deletes the vertical tab, the form feed and the next-line character as control codes instead of converting them to line breaks. And it leaves the line and paragraph separators U+2028 and U+2029 unchanged. See also how to remove extra spaces.

Whitespace in documents and on web pages

In a word processor, whitespace is shown on request. Press the ΒΆ button on the Home tab in Word, or Ctrl + Shift + 8 on Windows and Cmd + 8 on a Mac, and spaces, tabs and paragraph ends become visible marks. Our guide to showing hidden characters lists the symbols.

On a web page, the browser collapses runs of spaces, tabs and line breaks in the HTML source into a single space when it draws the text. That is why extra spaces typed into HTML do not show. A non-breaking space is the usual way to keep a gap, and the CSS rule white-space: pre keeps all whitespace as written. The entities for these are collected in our guide to the HTML space.

Common problems

Quick answers

How many whitespace characters are there? Unicode defines about two dozen with the White_Space property, including the ordinary space, tab, line breaks and the special spaces. Which ones a program treats as whitespace depends on the program.

Is a newline whitespace? Yes. A line feed and a carriage return both count.

Is a non-breaking space whitespace? Yes, in most languages. It is a space that does not allow a line break.

Normalize unusual spaces and extra whitespace. The cleaner turns special spaces into plain ones, collapses repeats and trims line ends. Open the AI Text Cleaner

Related guides