Whitespace Cleaner
Trim ends, collapse spaces, remove all whitespace, remove tabs, convert CRLF/LF
Whitespace cleaner: the six cleanup actions and where they apply
What each of the six buttons does
| Action | Behaviour | Fits |
|---|---|---|
| Trim ends | Per line, strip leading and trailing whitespace | Text copied from web pages, spreadsheets, PDFs — the most common cleanup |
| Collapse spaces | Compress runs of spaces and tabs into a single space | Fixing misaligned text from broken layout |
| Remove all whitespace | Delete every whitespace character, including newlines | Compress to one line, strip spaces from identifiers |
| Remove tabs | Delete tab characters only, keep spaces | Switch tab indentation to space indentation (but does not add spaces — see below) |
| CRLF to LF | Convert Windows line endings to Unix line endings | Committing to Git, running on Linux, writing shell scripts |
| LF to CRLF | Convert Unix line endings to Windows line endings | For old editors like Windows Notepad |
The newline trap: an invisible \r silently corrupts data
Line endings are not all the same, and that is a common root of cross-platform failures:
| System | Byte sequence | Note |
|---|---|---|
| Unix / Linux / modern macOS | \n (LF, 0x0A) | De facto standard; Git and most tools default to it |
| Windows | \r\n (CRLF, 0x0D 0x0A) | The historical habit of Notepad and friends |
| Old Mac (before OS 9) | \r (CR, 0x0D) | Rare now, but occasionally appears in legacy data |
The most typical failure looks like this: two lines appear completely identical, yet an invisible \r is attached. The symptoms include:
- A whole-file diff comes up red, though the naked eye sees no difference.
- A shell script reports
command not foundorbad interpreter— the\ris treated as part of the interpreter path. - The last CSV column gains an invisible character, and length validation fails on import.
- Concatenating a
\r-carrying value into a URL or JSON produces an illegal-character error. - A
$anchor in a regex fails to match (because the\rsits between the line end and the$).
So "CRLF to LF" is not merely a formatting preference; it is the first step when debugging "identical but somehow wrong" problems.
Tab-to-space is not a simple delete
"Remove tabs" only removes the tab character; it does not insert equal-width spaces. So \tif (x) becomes if (x) — the indentation level vanishes rather than turning into four spaces.
That is usually not what you want for code. To truly "tab to 4 spaces", use a replacement action: in the find-and-replace tool, replace \t (regex mode) with four spaces. A tab also matches directly as \t in regex, so the swap is straightforward.
The reverse request is also common: convert space indentation to tabs (to shrink file size or unify a team convention). That is finding (four spaces) and replacing with \t; handle it from the deepest indentation level outward, or it goes wrong. For that kind of formatting, an editor or a tool like Prettier is more reliable.
Collapse spaces does not touch newlines
"Collapse spaces" only processes spaces and tabs; it leaves newlines alone. So paragraph structure is preserved. If you also crush the newlines, the whole text becomes one line — that is the effect of "remove all whitespace".
When you need "compress several lines into one line while keeping a single space between words", the correct two steps are: first replace newlines with a space (in the find-and-replace tool, regex \s*\n\s* replaced by one space), then collapse the remaining runs of spaces.
A practical processing order
For cleaning text copied from outside, this order is recommended:
- CRLF to LF. Unify line endings first, so later steps have consistent assumptions.
- Trim ends. Strip per-line leading/trailing whitespace, clearing most formatting noise.
- Remove tabs or replace with spaces. Decide by the target format.
- Collapse spaces. Skip this if you need to preserve alignment.
- Drop blank lines / dedupe. Finish with the line dedupe and sort tool.
This order keeps each step's input clean, avoiding the chain reaction where "whitespace from the previous layer breaks matching in this layer". All steps happen locally in the browser.
FAQ
Does "Trim ends" work on the whole block or per line?
Per line: leading and trailing whitespace of each line is removed, while spaces inside the line are kept.
What are CRLF and LF?
Windows uses carriage return + line feed (CRLF, \r\n) as line breaks, while Unix / macOS and most code files use line feed (LF, \n). Conversion is used for cross-platform alignment.