toolready. Whitespace Cleaner

Whitespace Cleaner

Trim trailing spaces, normalize tabs, strip invisible characters.

What this does

Eight independent cleanups you tick on and off, applied to the input box and written to a read-only output box as you type. Nothing is destructive — the original stays where you pasted it, so you can toggle an option and compare. Five are on when the page loads: trim trailing spaces, collapse three or more blank lines, normalize CRLF to LF, strip zero-width characters and strip the BOM. Trim leading spaces, collapse runs of spaces, and tabs to spaces are off until you ask for them. All of it is string work done in your browser.

How do I strip trailing whitespace from every line?

  1. Paste the text into Input — trailing-space removal is already ticked.
  2. Add Trim leading spaces if you also want the indentation gone.
  3. Copy the Output box.
with trim leading, trim trailing and collapse blank lines on
(· marks a space)

input            output
··hi··           hi
(blank)          (blank)
(blank)          bye
··bye··

Trimming looks only for spaces and tabs at the edge of a line, so a line padded with non-breaking spaces is left alone.

In what order are the cleanups applied?

BOM, then zero-width characters, then newline normalization, then tabs to spaces, then collapsing runs of spaces, then trailing trim, leading trim, and finally blank-line collapsing. The order is what makes the common combination work: a line containing nothing but spaces is emptied by the trailing trim first, so the blank-line pass then sees a real run of newlines and collapses it. Run the passes in the other order and those lines would survive.

What are zero-width characters and why remove them?

They are real code points that occupy no visual space: zero-width space (U+200B), zero-width non-joiner (U+200C), zero-width joiner (U+200D), word joiner (U+2060), the byte-order mark (U+FEFF) and the soft hyphen (U+00AD). They arrive with text copied from documentation sites, PDFs and chat clients, and they count as characters — so a pasted API key stops matching, a JSON file fails to parse at column 1, and a search for a term in your own file finds nothing. Because U+FEFF is on that list, ticking this option removes stray byte-order marks throughout the document, not just the leading one that the separate BOM option targets.

Does this fix non-breaking spaces from Word?

No — and it is worth being clear about it, because it is the thing people usually come looking for. A non-breaking space (U+00A0) is a visible space character, not an invisible one, and none of these options touch it. Neither do the other Unicode spaces such as the en space or the narrow no-break space, or smart quotes and em dashes. To convert those, use find and replace in regex mode with a pattern like \u00a0 and a plain space as the replacement.

What does the tabs-to-spaces option do?

It replaces every tab character in the document with a run of spaces of the width you choose, from 1 to 16. It is a straight substitution rather than a tab-stop calculation, so a tab used to align a column mid-line becomes that fixed number of spaces regardless of where the line had reached. There is no conversion in the opposite direction. For related tidy-ups afterwards, see sort and dedupe lines or check the result with the character counter.