Whitespace Cleaner

Trim, collapse and remove whitespace from text.

  • Runs locally in your browser
  • No upload required

Try it

Processed entirely in your browser; nothing is uploaded.

0 keeps tabs; 1–8 expands each tab to that many spaces.

Result
hello world next line
Removed lines
0
Removed characters
9
hello world

next line

Supported formats

Input
text, boolean, number
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Cleaned the text, removing 10 character(s).

How it works

  • Normalised CRLF and lone CR line endings to LF.
  • Expanded each tab to 2 space(s).
  • Collapsed runs of two or more spaces to one.
  • Trimmed leading and trailing whitespace on every line.
  • Dropped lines that were empty after trimming.
  • Only whitespace is changed; other characters are preserved exactly.
  • The clean-up is idempotent for a fixed option set.

Methodology

  1. Normalise CRLF and lone CR to LF.
  2. Expand tabs to the chosen number of spaces, or keep them when the width is zero.
  3. Collapse runs of two or more spaces into one when space collapsing is enabled.
  4. Trim leading and trailing whitespace on each line when line trimming is enabled.
  5. Remove lines that are empty after trimming when blank-line removal is enabled.

Usage

  1. Paste the text to clean.
  2. Choose which whitespace operations to apply.
  3. Run the tool and copy the cleaned text.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Collapse and trim

jsonSelect to copy
{
  "text": "  hello   world  \n\n  next line ",
  "trimLines": true,
  "collapseSpaces": true,
  "removeBlankLines": true,
  "tabWidth": 2
}

Expand tabs

jsonSelect to copy
{
  "text": "a\tb",
  "trimLines": false,
  "collapseSpaces": false,
  "removeBlankLines": false,
  "tabWidth": 4
}

Trim only

jsonSelect to copy
{
  "text": "  keep   inner  spaces  ",
  "trimLines": true,
  "collapseSpaces": false,
  "removeBlankLines": false,
  "tabWidth": 0
}

Limitations

Pasted text carries formatting

Text copied from a document editor often mixes tabs, non-breaking spacing and trailing spaces. Cleaning it reproducibly makes diffs and downstream processing predictable.

Frequently asked questions

In what order are the options applied?
Newlines are normalised first, then tabs are expanded, then runs of spaces are collapsed, then lines are trimmed, and finally blank lines are removed.
Is the result stable if I run it twice?
Yes. With the same options, cleaning already-cleaned text changes nothing.

Sources

  1. ECMA-262: ECMAScript Language Specification — White Space — Ecma International
  2. MDN Web Docs — Regular expressions — Mozilla