Remove Extra Spaces and Invisible Characters
Remove extra spaces, ragged indentation and stray blank lines, and get a count of the invisible characters you could not have seen. Some whitespace problems are visible. The worse ones are not: the non-breaking space that makes a compiler reject code that looks perfect, the zero-width space that makes two identical-looking strings compare as different. The counts tell you whether the text was merely untidy or actively booby- trapped.
Use this without the search next time. Prathom Workbench puts Prathom's tools in your toolbar.
Add to Chrome — freeWhat it does
- Collapses runs of spaces and tabs, trims line ends, drops blank lines
- Converts non-breaking and typographic spaces to plain spaces
- Deletes zero-width spaces, BOMs, soft hyphens, and word joiners
- Reports separate counts for normalized and removed characters
How to use Whitespace Remover
- 1
Paste the suspect text
Especially text copied from Word, Google Docs, Slack, or a web page — the environments most likely to have decorated it with characters you cannot see.
- 2
Read the two counters
"Invisible removed" and "Spaces normalized" quantify what was hiding in the text. Non-zero numbers on text that looked fine are the smoking gun for the bugs described below.
- 3
Adjust the visible cleanup
Collapsing runs, trimming ends, and dropping empty lines are each a separate switch, so you can normalize the invisible layer while leaving the visual layout alone.
- 4
Copy the clean version
The output contains only plain spaces, plain line breaks, and your characters — safe for code, spreadsheets, and string comparison.
How it works
Cleaning happens in two distinct passes, because the two problems are different in kind.
The character pass runs first. Space-like characters — the non-breaking space, the typographic en/em/thin family, the ideographic space — are converted to plain spaces, because they separate words and deleting them would fuse text together. Truly zero-width characters — the zero-width space, the byte-order mark, the soft hyphen, the word joiner — are deleted outright, because they occupy no visual space and removing them changes nothing a reader sees. Each pass counts its victims separately, which is how the tool can tell you that a paragraph contained three invisible characters rather than leaving you to take it on faith.
The line pass then works on what remains: runs of spaces and tabs collapse to single spaces, line ends are trimmed, and empty lines are dropped if asked. These operate per line, so the text's overall line structure is never rearranged.
One family of invisible characters is deliberately spared: the zero-width joiner and non-joiner, which shape emoji sequences and connect or separate letters in scripts across South Asia and the Middle East. A whitespace cleaner has no business editing those.
Why the counts matter
"It looks fine" is worthless evidence with this class of problem — the whole failure mode is that broken text is visually indistinguishable from clean text. The two counters turn the invisible into a number. Zero means the text really was clean and your bug is elsewhere; a non-zero count both confirms the diagnosis and fixes it in the same click.
When you'd use this
Repairing code pasted from Slack, a blog, or a PDF before running it. Cleaning spreadsheet cells whose lookups fail on visually identical values. Normalizing text before comparing two versions, so a diff shows real edits rather than whitespace noise. De-fingerprinting text that may carry zero-width watermarks. Tidying terminal output for a report.
Where these characters come from
Knowing the source usually tells you whether to expect more of them.
Word processors are the largest contributor. Non-breaking spaces get inserted automatically to stop a line breaking between a number and its unit, and optional hyphens get added to control word splitting. Neither is visible, and both travel with the text when it is copied.
Web pages contribute zero-width spaces, usually placed inside long URLs or identifiers so they can wrap inside a narrow column. Copy the URL and you copy the break points, which is why a link that looked correct fails when pasted into a browser.
PDFs are the worst offenders, because their text is a set of positioned glyph runs rather than sentences. Extracting it produces spacing that reflects where the characters sat on the page, so alignment padding, column gutters and line-ending decisions all arrive as literal whitespace.
Chat applications and rich text editors add their own, often replacing typed spaces with non-breaking ones to preserve runs of spacing that HTML would otherwise collapse. This is the usual reason code pasted from a chat fails to compile with an error pointing at a line that looks perfectly normal.
What this deliberately does not touch
Two kinds of invisible character are left alone, and both would cause real damage if removed.
The zero-width joiner and non-joiner are not formatting. In Arabic, Persian, Hindi and many other scripts they control whether adjacent letters connect, which changes how a word is written and sometimes what it says. In emoji they bind sequences together — a family or a professional with a skin tone is several symbols joined by these characters, and stripping them leaves the components scattered. A whitespace cleaner removing either would be corrupting text while claiming to clean it.
Line breaks themselves are also left alone unless the empty-line option is on. Reflowing wrapped lines back into paragraphs requires deciding where paragraphs end, whether a trailing hyphen was a real hyphen or a line-break artifact, and whether an indented line is a quotation or continuation. Those are judgment calls that belong to a tool built for them, which is why Remove Line Breaks exists separately.
Tabs collapse to single spaces rather than being preserved. If you are cleaning a tab-separated file, that will destroy the field boundaries — clean the values rather than the file, or use a tool that understands the format.
Examples
Invisible characters from a product page
The input looks identical to the output — that is the point. Between "Price:" and the amount sat a non-breaking space (now a plain space), and after the price hid a zero-width space (now gone). Text like this fails searches and breaks CSV imports while passing every visual inspection you can give it.
Ragged spacing from a terminal capture
Runs of alignment spaces collapse to single ones, trailing whitespace disappears, and the stacked blank lines go — with the empty-line option switched on for this run. What was column alignment in a fixed-width terminal becomes ordinary prose spacing in a proportional font.
Frequently asked questions
Where do invisible characters even come from?
Word processors insert non-breaking spaces to control line wrapping and soft hyphens to control word splitting. Web pages use zero-width spaces to allow long URLs to wrap. Some systems even fingerprint text with patterns of zero-width characters. Copy any of that and the characters ride along invisibly, surfacing later as baffling failures in whatever consumed the text.
Why does my code fail to compile after pasting from a chat app?
Almost always a non-breaking space. Chat and document apps convert certain typed spaces to U+00A0, which renders identically to a space but is not one to a compiler's tokenizer — hence errors like "invalid character" pointing at a line that looks flawless. Running the snippet through this tool replaces every such character with a real space.
Why are zero-width joiners not removed?
Because they are load-bearing. The zero-width joiner is what fuses individual emoji into sequences like the family emoji, and together with the non-joiner it controls how letters connect in Persian, Arabic, and Indic scripts. Stripping them would corrupt names and emoji in the very text being cleaned, so this tool leaves them — a deliberate difference from cruder cleaners.
Is a non-breaking space deleted or replaced?
Replaced with an ordinary space, never deleted. A non-breaking space is still a word separator — "annual report" written with one is two words, and deleting the character would fuse them into "annualreport". The same logic applies to the whole typographic family: en spaces, em spaces, thin spaces, and the ideographic space all become one plain space.
Does this tool also remove line breaks?
Only fully empty lines, and only when that option is on. Reflowing wrapped lines into paragraphs is a different job with different judgment calls — hyphenation, paragraph detection — and it has its own tool: Remove Line Breaks. Splitting the two keeps each tool's options simple and its behavior predictable.
Further reading
- Windows Line Endings Cost 1.8% on Disk and Three Bytes CompressedEvery line of a Windows text file ends with two characters where a Unix one ends with one. It is the oldest formatting difference in computing and it is worth a measurement, because the size argument turns out to be the least important thing about it.
- How to Remove Duplicate Lines From a ListDeduplicating a list sounds like one operation with one right answer. It is actually four decisions, and getting any of them wrong either leaves duplicates behind or silently deletes rows you needed. The decisions are more interesting than the operation.
- The Invisible Characters That Break Your SpreadsheetTwo cells look identical, and the lookup returns nothing. A search for a name that is visibly right on screen finds no match. Both have the same cause: a character with no width sitting inside the text, put there by a word processor or a web page, doing nothing except making two strings unequal.