Remove Whitespace

Collapse runs of spaces, strip tabs, trim each line, swap out non-breaking spaces, or wipe every whitespace character in one pass. Runs in your browser.

Remove Whitespace Delete Line Breaks Online Text Cleaner Blank Line Remover soon Strip Whitespace soon
Input Load sample

How to use the whitespace remover

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

Six toggles cover every common case. Collapse multiple spaces is on by default and handles the most common scenario: long runs of spaces collapsing into one. Remove all whitespace wipes everything (spaces, tabs, newlines, non-breaking spaces) for code minification or hash-key prep. The four remaining toggles target specific symptoms (per-line trim, document-edge trim, tabs to spaces, non-breaking space conversion).

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 whitespace

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
JSON keys and string values cannot tolerate stray whitespace or tabs and most parsers fail on a non-breaking space slipped in by a smart editor. 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 95% of 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 and Google Docs auto-insert these. Press Shift+Space. 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 covers U+00A0. 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 the Remove all whitespace toggle.

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, Google Docs, and HTML editors slip these in when you press Shift+Space or when a smart-quote feature reflows your text. 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 for regular 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, use the per-toggle controls instead (Collapse multiple spaces, Convert tabs to spaces, Convert non-breaking spaces, Trim each line).

How many spaces does Convert tabs to spaces use?

By default, every tab character becomes four spaces. This matches most modern code editor defaults. If your source used a different tab width (two for JavaScript style, eight for older Unix files), convert in your editor first or convert here then use Collapse multiple spaces to normalize.

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 →