Remove Spaces

Remove spaces from text in one pass: delete every space and tab while keeping your line breaks, collapse double spaces, trim each line, swap out non-breaking spaces, or wipe every whitespace character. This whitespace remover runs in your browser.

Input Load sample

How to remove spaces and whitespace

1. Paste the text

Drop the messy text into the Input box. Tabs, double spaces, indentation, non-breaking spaces from Word and Google Docs, and stray trailing whitespace are all picked up. The tool reads Unix, Windows, and Mac line endings without any setup.

2. Pick the toggles

Nine toggles cover the common cases. Collapse multiple spaces is on by default and handles the most frequent job: long runs of spaces collapsing into one. Remove all spaces, keep line breaks deletes every space and tab but leaves each line on its own row, which is what most people mean by removing spaces from a list or a column of values. Remove all whitespace wipes everything (spaces, tabs, newlines, non-breaking spaces) for code minification or hash-key prep. The remaining toggles target specific symptoms (per-line trim, document-edge trim, blank-line removal, joining every line into one, tabs to spaces, non-breaking space conversion). Two presets set several toggles at once: Compact collapses spaces, converts non-breaking spaces, trims each line, removes blank lines and trims the document; Single line does the same and then joins every line into one line.

3. Clean and copy

Click Clean. The output appears on the right with a count of how many characters were removed. Use Copy to paste, or Download for a .txt file.

When you need to remove spaces

Whitespace creep happens any time text crosses a tool boundary. Five places where this tool earns its keep.

PDF copy-paste cleanup
PDFs export text with weird inter-word spacing, sometimes thin spaces or non-breaking spaces between every word. Turn on Collapse multiple spaces and Convert non-breaking spaces. The result reads like a normal paragraph.
JSON / API payload cleanup
A non-breaking space slipped in by a smart editor is not valid JSON whitespace, so a strict parser rejects it when it sits between keys and values. Run the payload through with Convert tabs and Convert non-breaking spaces both on.
Code formatting prep
Before running a code formatter, normalize tabs to spaces and collapse runs of spaces. Saves the formatter from second-guessing your indentation. Pair with the all-whitespace toggle if you want a hash-key.
CSV cell cleanup
A leading or trailing space in a CSV cell causes JOIN failures and broken VLOOKUPs. Turn on Trim each line to strip every cell's edges before saving the file.
Copy-from-Word cleanup
Microsoft Word and Google Docs sprinkle non-breaking spaces, double-space-after-period, and the occasional zero-width character. The combo of Collapse multiple spaces + Convert non-breaking spaces handles most paste-in damage.
Pre-hash text normalization
If you are computing a hash or comparison key over user-input text, whitespace differences will break the match. Turn on Remove all whitespace before hashing so "hello world" and "hello world" produce the same key.

The kinds of whitespace your text might contain

Not all whitespace is the same character. Word processors, PDF exports, and typographic tools insert several different kinds that look identical on screen but behave differently in search, comparison, and hashing.

NameCode pointBytesWhere it comes from
Regular spaceU+00200x20Every keyboard, every text file. The default whitespace.
Horizontal tabU+0009\tPress Tab. Used for indentation in source code and TSV files.
Non-breaking spaceU+00A0\xc2\xa0Word processors and web editors insert these, often through autocorrect or a non-breaking space shortcut. Common in HTML as  .
En-spaceU+2002\xe2\x80\x82Typesetting tools (LaTeX, InDesign). Wider than regular space.
Em-spaceU+2003\xe2\x80\x83Typesetting tools. Wider still.
Zero-width spaceU+200B\xe2\x80\x8bInvisible. Used for line-break hints in URLs and CJK text.
Line feed (newline)U+000A\nPress Enter on Unix and modern Mac. Hard line break.
Carriage returnU+000D\rPress Enter on Windows (paired with LF as CRLF). Classic Mac used CR alone.

The Convert non-breaking spaces toggle turns U+00A0, the en-space, the em-space and the other Unicode spaces into regular spaces, and deletes zero-width spaces. The Remove all whitespace toggle covers everything in this table, including the en-space and em-space. If you spot a different exotic space character that the tool is leaving behind, paste it into the input box and click Clean: U+2002 through U+200B are all handled by the all-whitespace mode.

If you need to collapse a multi-line block down to a single line with a chosen separator instead of just stripping whitespace, use Text to One Line. If you need to remove only the newline characters while keeping spaces intact, use Remove Line Breaks. Pair this tool with Twitter character counter when you are buying back characters near a post-length limit.

Related tools

Frequently asked questions

What counts as whitespace?

Whitespace is any character that prints as blank space. The common ones are the regular space, the tab, and the newline. There are also less visible ones: the non-breaking space, the en-space, the em-space, and a handful of Unicode spaces used by typographic tools. This page targets horizontal whitespace (spaces and tabs and their cousins) and leaves your line breaks alone unless you turn on Remove blank lines, Join lines into one line, or Remove all whitespace.

How do I collapse double spaces without losing my paragraph layout?

Leave the default Collapse multiple spaces toggle on and leave every other toggle off. Runs of two or more spaces in a row become a single space. Tabs, newlines, and non-breaking spaces are not touched.

What is a non-breaking space and why would I want to convert it?

A non-breaking space (Unicode U+00A0) looks the same as a regular space but tells the renderer not to wrap a line at that point. Word processors and HTML editors slip these in, often through autocorrect or a non-breaking space shortcut. They cause search-and-replace to miss matches and they break JSON if the receiving tool only expects ASCII. Turn the Convert non-breaking spaces toggle on to swap them, and the other Unicode spaces, for regular spaces. Zero-width spaces are deleted rather than turned into visible spaces.

What is the difference between Trim each line and Remove leading/trailing whitespace of doc?

Trim each line strips spaces, tabs, and non-breaking spaces from the start and end of every line, one line at a time. Remove leading/trailing whitespace of doc only trims the very top and very bottom of the whole document. Use the per-line version for indented code or messy paste-ins. Use the whole-document version when the body of the text is fine and you just want to drop the empty lines surrounding it.

Will Remove all whitespace also remove line breaks?

Yes. The Remove all whitespace toggle wipes every whitespace character, including line breaks, tabs, and non-breaking spaces. The result is a single continuous string with no spaces. If you want to keep line breaks but drop the spaces and tabs, turn on Remove all spaces, keep line breaks instead: every space, tab and non-breaking space goes, and each line stays on its own row.

How many spaces does Convert tabs to spaces use?

Every tab character becomes four spaces, a common code editor setting. The four spaces are kept even when Collapse multiple spaces is on. If your source used a different tab width (two or eight are also common), convert the tabs in your editor first.

I'm flattening whitespace in code snippets and minified payloads before pasting them into a chat. Is the snippet captured anywhere?

No. Whitespace stripping happens in your browser. Code snippets, JSON payloads, and any other source you paste stay in the textarea. We make no API call to process them.

Can the tool handle pasted text from Word or Google Docs?

Yes. Word and Google Docs commonly insert non-breaking spaces, smart quotes, and zero-width characters. Turn on Convert non-breaking spaces and Trim each line. Collapse multiple spaces takes care of the double-space-after-period habit. The result is plain ASCII whitespace you can paste anywhere. See also: All text removers.

More wordcounter.ai tools

Other tools you might find useful.

Browse the full catalog →