Whitespace Cleaner

Type or paste your text, pick which cleanup rules to apply β€” the result updates live.

How Whitespace Cleaner Works

This tool cleans up messy whitespace in any text you type or paste -- trimming stray spaces from the start and end of lines, collapsing repeated spaces and tabs down to one, removing empty lines, and trimming the whole block of text -- with each cleanup rule individually toggled by its own checkbox.

Formula & Method

The text is first split into lines. If "Trim spaces at the start/end of each line" is checked, each line has leading and trailing whitespace removed. If "Collapse multiple spaces/tabs into one" is checked, any run of one or more spaces or tabs within a line is replaced with a single space (this doesn't touch line breaks themselves). If "Remove blank lines" is checked, any line that is empty or only whitespace is dropped entirely. The remaining lines are rejoined with line breaks, and if "Trim whitespace from the whole text" is checked, any leading or trailing whitespace on the joined result is removed. All four options are on by default and independently toggleable.

Worked Example

For the text "  Hello   world  " followed by a blank line, a tab-indented line "This   is  a   test.", two more blank lines, and "  Goodbye.  " (55 characters total), with all four options checked the tool outputs exactly "Hello world" / "This is a test." / "Goodbye." across three lines (36 characters) -- removing 19 characters, about 35% shorter.

Frequently Asked Questions

Does collapsing spaces also merge separate lines together?
No -- the space-collapsing rule only affects runs of spaces and tabs within a single line. Line breaks are handled separately by the "Remove blank lines" option, so the two rules don't interfere with each other.
What counts as a "blank line"?
Any line that is completely empty or contains only whitespace (spaces, tabs) is treated as blank and removed when that option is checked -- a line with even one visible character is kept.
Can I turn off individual cleanup rules?
Yes -- each of the four rules (trim lines, collapse spaces, remove blank lines, trim whole text) has its own checkbox, so you can combine only the cleanups you actually want, for example collapsing spaces without removing blank lines.
Does this tool remove whitespace characters like non-breaking spaces?
It targets regular spaces and tabs specifically for collapsing, and standard whitespace (including newlines) for trimming. Special characters like non-breaking spaces ( ) that don't match a plain space may not be collapsed the same way.