Whitespace and Blank Line Remover
Clean up messy text by trimming lines, collapsing repeated spaces, removing blank lines and stripping the invisible characters that survive a copy and paste.
Three different definitions of "whitespace", one panel
The options above do not share a notion of what they are removing:
| Option | What it actually covers |
|---|---|
| Convert non-breaking spaces | U+00A0 only |
| Convert tabs | U+0009 only |
| Collapse multiple spaces | U+0020 only |
| Trim / remove blank lines | the full Unicode whitespace set |
So the collapse pass and the trim pass disagree.
8 whitespace characters that
trim() would strip from the end of a line survive untouched in the middle
of one, because / {2,}/ only knows about the ASCII space:
no-break space, ogham space mark, em space, thin space, narrow no-break space, medium mathematical space, ideographic space, byte order mark. Paste a line with two em spaces in the
middle and "collapse multiple spaces" leaves both. It is not broken — it does what it says,
and what it says is narrower than what people read it as.
Two zero-width characters, classified oppositely
| Character | Code | Matched by /\s/ | Removed by trim() |
|---|---|---|---|
| space | U+0020 | yes | yes |
| tab | U+0009 | yes | yes |
| no-break space | U+00A0 | yes | yes |
| ogham space mark | U+1680 | yes | yes |
| em space | U+2003 | yes | yes |
| thin space | U+2009 | yes | yes |
| narrow no-break space | U+202F | yes | yes |
| medium mathematical space | U+205F | yes | yes |
| ideographic space | U+3000 | yes | yes |
| zero-width space | U+200B | no | no |
| zero-width non-joiner | U+200C | no | no |
| word joiner | U+2060 | no | no |
| soft hyphen | U+00AD | no | no |
| byte order mark | U+FEFF | yes | yes |
U+FEFF, the byte order mark, takes no visible space and JavaScript counts it
as whitespace. U+200B, the zero-width space, takes no visible space and
JavaScript does not. Two invisible characters, one stripped and one kept, and nothing about
either name tells you which is which — the zero-width space is a formatting character in
Unicode's classification, while the byte order mark, despite its name, is treated as a space
by the language.
The ones that survive everything
4 characters here are invisible and pass through every option this page offers, because none of them is whitespace by any definition the tool uses: U+200B zero-width space, U+200C zero-width non-joiner, U+2060 word joiner, U+00AD soft hyphen. These are exactly what a paste from a word processor, a PDF or a styled web page leaves behind.
A worked example: a line with a zero-width space, three ordinary spaces and a soft hyphen goes in at 16 characters and comes out at 14. The three spaces really were collapsed, so the tool did its job. It still contains both invisibles, and you can only see 12 characters in a string that reports 14. If a value refuses to match something it visibly equals, this is usually why — and comparing the length against the number of characters you can count is the fastest way to catch it.
How to use
- Paste the text you want cleaned.
- Choose which operations to apply.
- Review the result before copying.
- Check for invisible characters if text still misbehaves.
Frequently asked questions
Why does pasted text have strange spacing?
Copying from a PDF, a web page or a word processor often brings non-breaking spaces, tabs, and line breaks at the end of every visual line rather than every paragraph. They look like ordinary spaces and behave differently, which is why the text reflows badly.
What is a non-breaking space?
A space that prevents a line break at that point. It is invisible and indistinguishable from an ordinary space on screen, but a search for a normal space will not find it — which is why find-and-replace sometimes appears not to work at all.
What is a zero-width character?
A character with no visual width at all, such as the zero-width space or joiner. They occur legitimately in some scripts and in emoji sequences, and illegitimately in text copied from certain sites. They can break string comparison, search and validation in ways that are very hard to diagnose by looking.
Should I remove trailing whitespace from code?
Generally yes. It produces noisy diffs where a line appears changed but is not, and many linters flag it. Markdown is the notable exception — two trailing spaces there mean a line break, so stripping them silently changes the rendered output.
What is the difference between trimming and collapsing?
Trimming removes whitespace from the start and end of a line; collapsing reduces runs of whitespace inside the line to a single space. They are independent, and text pasted from a document often needs both.
Why do tabs and spaces cause so much trouble?
Because a tab's width depends on the viewer's settings while a space is fixed, so mixed indentation lines up in one editor and not another. Python treats the two as different indentation and will refuse to run a file that mixes them inconsistently.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.