Whitespace Cleaner
Trim, collapse and remove whitespace from text.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
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
- Normalise CRLF and lone CR to LF.
- Expand tabs to the chosen number of spaces, or keep them when the width is zero.
- Collapse runs of two or more spaces into one when space collapsing is enabled.
- Trim leading and trailing whitespace on each line when line trimming is enabled.
- Remove lines that are empty after trimming when blank-line removal is enabled.
Usage
- Paste the text to clean.
- Choose which whitespace operations to apply.
- 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
{
"text": " hello world \n\n next line ",
"trimLines": true,
"collapseSpaces": true,
"removeBlankLines": true,
"tabWidth": 2
}Expand tabs
{
"text": "a\tb",
"trimLines": false,
"collapseSpaces": false,
"removeBlankLines": false,
"tabWidth": 4
}Trim only
{
"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
- ECMA-262: ECMAScript Language Specification — White Space — Ecma International
- MDN Web Docs — Regular expressions — Mozilla
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.