Home/Text tools/Whitespace cleaner

Text tool

Whitespace Cleaner

Text copied from Word, PDFs and spreadsheets carries invisible characters that look fine but break things downstream. Switch on only the rules you need and see the result update live.

Changed

0 characters removed

Invisible characters and where they come from

Text that looks identical on screen can be built from different underlying characters, and most editors give no visual clue which one you have. This causes real bugs: a string that "looks" equal fails an exact-match comparison, or a page layout that "looks" fine wraps unexpectedly.

Common invisible characters, where they come from, and what they break
CharacterTypically comes fromWhat it breaks
Non-breaking space U+00A0Pasting from Word or a web page (used to stop line breaks mid-phrase)Looks identical to a normal space but fails exact string-equality checks and \s in some regex contexts
Zero-width space U+200BCopying from some CMS editors and PDF exports; occasionally inserted deliberately to break up long words for wrappingInvisible — a word count or search that should find a match silently fails because there is a "gap" mid-word
Tab \tSpreadsheet cell copies (Excel/Sheets separate columns with tabs), indented codeRenders as a variable width depending on the viewer, misaligning anything expecting fixed-width spacing
CRLF line ending \r\nWindows-authored files and Windows-side copy/pasteSome Unix tools and diff utilities show every line as changed if one file uses CRLF and the other LF
LF line ending \nMac, Linux, and virtually all web text areasOpened raw in old Windows Notepad, a whole file can show as one unbroken line

The NBSP case is the one that catches people out most: "10 km" pasted from a webpage can contain U+00A0 between the number and unit instead of a normal space. It displays identically, copies identically, and then fails a form validator or a spreadsheet formula that compares it against a typed-in "10 km", because the two strings are not actually equal at the byte level.

Questions people ask

Why is trailing-space stripping on by default but leading-space stripping isn't?

Trailing spaces are almost always accidental — nobody deliberately leaves invisible spaces at the end of a line. Leading spaces are sometimes meaningful indentation, in code or in nested lists, so removing them by default risks breaking structure you meant to keep.

What counts as a "blank line" for the remove-blank-lines rule?

A line that is empty, or contains only spaces and tabs, after the other rules above it have already run. If double-space collapsing and trim rules are on, a line of nothing but spaces becomes truly empty first, then gets removed.

Does converting tabs to spaces change indentation width?

Each tab becomes exactly four spaces, a common default. If your source used a different tab width (2 or 8 are also common), the visual indentation will shift — check the result before relying on exact column alignment.

Is this safe to run on code?

Collapsing double spaces can break code where repeated spaces are meaningful (some formatting styles, ASCII art, aligned comments) — leave that rule off for code. Line-ending normalisation and trailing-space stripping are almost always safe.

Cleaning text for somewhere else?

Diffing, deduplication and case conversion sit right next door.

See all text tools →