RunTheTests
/

Whitespace Cleaner

Collapse extra spaces and trim every line.

What you provide

How this calculation works

Repeated spaces within a line are collapsed to one, leading and trailing spaces are trimmed from every line, and long runs of blank lines are reduced.

What the results mean

Per-line trim
Each line is cleaned independently, so indentation you did not intend disappears while paragraph breaks survive.
Non-breaking spaces
Text copied from a web page or a word processor often contains these instead of ordinary spaces. They look identical and behave differently — searches miss them, and layouts refuse to wrap at them.
Tabs
Converted to a single space when they appear inside a line, which is what you want for prose and not what you want for code or anything column-aligned.

Common problems and fixes

A search will not match text that is clearly there
Usually a non-breaking space where you assumed a normal one, which is what a word processor inserts after certain punctuation and what copying from a web page frequently produces. Cleaning the whitespace converts them to ordinary spaces, after which the search behaves as expected.
My indentation disappeared
Leading whitespace is trimmed from every line by design, which is right for prose pasted out of a document and wrong for code or anything column-aligned. For source code, use your editor's own trailing-whitespace and indentation settings, which understand the difference between meaningful and accidental leading space.
There are still large gaps between paragraphs
Runs of three or more blank lines are reduced to a single paragraph break, and single blank lines are left alone deliberately, since removing them would destroy the paragraph structure. If gaps remain, they are likely to be lines containing spaces rather than genuinely empty ones — cleaning trims those, so a second pass resolves it.

Frequently asked questions

Does it remove all blank lines?

No — it reduces runs of three or more blank lines to a single paragraph break, preserving the structure while removing excess.

What exactly counts as whitespace here?

Ordinary spaces, tabs, non-breaking spaces and the various Unicode space characters that word processors and web pages introduce — thin spaces, en spaces and the like. They render nearly identically and behave quite differently in searches, comparisons and line wrapping, which is why converting them all to a plain space is usually what people actually want.

Will this break my Markdown?

Partly, so check the result. Markdown uses two trailing spaces at the end of a line to mean a hard break, and trimming removes them. Indentation-based structures — nested lists, indented code blocks — also rely on leading whitespace that gets trimmed. For prose it is safe; for structured Markdown, review before replacing the original.

Put this on your own site

Free to embed, no attribution required beyond the source link the frame carries itself. It runs entirely in your visitor's browser, sets no cookies and loads no third-party script.

Embed code
<iframe src="https://runthetests.com/embed/whitespace-cleaner/" width="100%" height="560" style="border:1px solid #e5e5e5;border-radius:8px" title="Whitespace Cleaner" loading="lazy"></iframe>

Preview it at https://runthetests.com/embed/whitespace-cleaner/. Embedded pages are marked noindex, so yours stays the canonical copy — not this one.

More in Text