WR
Whitespace Remover
Trim lines, collapse repeated spaces, drop blank lines, or strip all whitespace entirely.
More Text & Writing Tools
Before
After
Removed
How to Use Whitespace Remover
Paste text into the box and clean up its whitespace with four independent controls: trim each line, collapse multiple spaces/tabs into one, remove blank lines entirely, or strip every whitespace character from the whole text. The first three combine freely; the fourth is an all-or-nothing override. A before/after character count shows exactly how much was removed. Runs entirely in your browser.
About Whitespace Remover
Whitespace problems are some of the most common and most invisible issues in pasted or copied text. Text copied out of a PDF, an old email thread, a spreadsheet cell, or a legacy system export frequently carries trailing spaces at the end of lines, tabs mixed with spaces, doubled-up spaces where a line was edited and re-typed over itself, and stray blank lines left behind by inconsistent formatting. None of this is visible to the eye in a normal text field — a trailing space looks identical to no trailing space until you paste the text somewhere that treats whitespace meaningfully, like a CSV column, a config file, or a string comparison that unexpectedly fails.
This tool separates whitespace cleanup into four independent operations rather than one blunt "clean it all up" button, because different situations call for different combinations. Trimming leading/trailing whitespace on each line removes exactly what its name says — spaces or tabs at the very start or end of each line — without touching whitespace in the middle of a line, which matters if a line's internal spacing (like column alignment in a plain-text table) is meaningful and should be preserved. Collapsing multiple spaces/tabs into one addresses the doubled-space or mixed-tab-and-space problem within a line, replacing any run of consecutive spaces or tabs with a single space, which is exactly what you want for prose where extra internal whitespace serves no purpose but is visually distracting and can break certain parsers that expect single-space-separated tokens. Removing blank/empty lines entirely drops any line that is empty after trimming, which is useful for cleaning up a list or code snippet that has accumulated stray blank lines from repeated copy-pasting or editing.
These first three options are independent checkboxes and combine freely — you might want to trim lines and collapse spaces but keep blank lines as paragraph breaks, or remove blank lines but leave internal spacing untouched. All default to checked, since trimming, collapsing and blank-line removal together represent the most common "just clean this up" request and produce a sensible, non-destructive result for the overwhelming majority of pasted text.
The fourth option, remove all whitespace entirely, is fundamentally different in kind rather than degree: it is not "more aggressive trimming," it strips every space, tab, newline and other whitespace character from the entire text, collapsing it into one unbroken string with no whitespace anywhere at all — including between words that were never meant to run together. This is occasionally exactly what's needed (checking whether two strings are equal ignoring all whitespace differences, or generating a whitespace-free identifier from a phrase), but it is a fundamentally destructive, all-or-nothing transformation incompatible with any notion of "clean up the formatting while keeping it readable." Because of that, checking this option deliberately overrides and disables the other three — there is no meaningful way to combine "strip literally everything" with "but also trim each line first" — so the interface visually greys out and ignores the other three checkboxes whenever this one is active, making the mutual exclusivity explicit rather than leaving you to wonder why your other settings stopped having any visible effect.
The before/after character count (using Unicode-code-point-safe counting, consistent with the rest of this tool suite) makes the effect of your chosen options immediately quantifiable, which is a useful sanity check before pasting cleaned text into a size-constrained field or committing it somewhere.
Details & Tips
Processing order when "remove all whitespace" is unchecked: (1) if "trim each line" is checked, every line has leading/trailing whitespace stripped independently; (2) if "collapse multiple spaces/tabs" is checked, every run of one-or-more spaces or tabs within each line is replaced with a single space; (3) if "remove blank lines" is checked, any line that is empty after trimming is dropped entirely from the output; the remaining lines are rejoined with newlines.
When "remove all whitespace entirely" is checked, none of the above three steps run — instead, every whitespace character (spaces, tabs, newlines, and other Unicode whitespace matched by JavaScript's `\s`) is stripped from the raw input in a single pass, producing one unbroken string. The other three checkboxes are visually disabled and have no effect while this option is active, since there is no coherent way to combine them with total whitespace removal.
Worked example 1 — input (with trailing spaces and a doubled internal space, default options: trim ON, collapse ON, remove-blank ON):
```
Hello World
This has extra spaces.
```
Step 1 (trim each line): `Hello World` / `` / `This has extra spaces.`
Step 2 (collapse spaces): `Hello World` / `` / `This has extra spaces.`
Step 3 (remove blank lines): the middle empty line is dropped.
Final output:
```
Hello World
This has extra spaces.
```
Worked example 2 — same input with "remove all whitespace entirely" checked instead: every space and newline is removed, producing `HelloWorldThishasextraspaces.` as one unbroken string — note this also merges words that were never meant to be joined, which is the expected (if aggressive) behaviour of this mode.
Worked example 3 — trim ON, collapse OFF, remove-blank OFF on the same input: only leading/trailing whitespace per line is removed, so the doubled internal space in "This has extra spaces." is left untouched, and the blank line in the middle is kept (though now fully empty rather than whitespace-only).
The before/after character counts use the same Unicode-code-point-safe counting (`Array.from(text).length`) as the rest of this tool suite, so the reported character delta is accurate even when the text contains accented letters or emoji.
Frequently Asked Questions
What does "trim each line" actually remove?
Only leading and trailing whitespace on each individual line — spaces or tabs at the very start or end. Whitespace in the middle of a line is untouched by this option.
What is the difference between trimming and collapsing spaces?
Trimming removes whitespace only at the start/end of each line. Collapsing replaces any run of multiple consecutive spaces or tabs anywhere within a line with a single space.
Why is "remove all whitespace" mutually exclusive with the other options?
Because it is a fundamentally different, all-or-nothing operation — it strips every whitespace character from the entire text, including spaces between words, rather than tidying formatting while keeping the text readable. Combining it with "trim" or "collapse" would not make sense, so the other options are disabled while it is active.
Will "remove all whitespace" merge words together?
Yes, this is expected behaviour — it removes every space, tab and newline including the ones between words, producing one unbroken string. Only use it when you specifically want whitespace-free output.
Does "remove blank lines" remove lines that only contain spaces?
Yes, a line is considered blank if it is empty after trimming, so a line containing only spaces or tabs (but no visible characters) is removed just like a truly empty line.
What are the default settings?
Trim lines, collapse spaces, and remove blank lines are all checked by default, since together they represent the most common "clean this up" request. "Remove all whitespace" is unchecked by default.
How is the before/after character count calculated?
Using Unicode code-point-safe counting, the same method used throughout this site's text tools, so accented letters and most emoji are each counted as one character rather than being miscounted.
Can I keep blank lines as paragraph breaks while still trimming and collapsing spaces?
Yes, uncheck "Remove blank lines entirely" while leaving the other two checked, and blank lines between paragraphs will be preserved while trailing whitespace and doubled internal spaces are still cleaned up.
Does this tool touch tabs used for code indentation?
If "collapse multiple spaces/tabs" is checked, a run of leading tabs used for indentation would be collapsed to a single space, which would break code indentation — leave that option unchecked if you need to preserve tab-based indentation in code.
Is my text uploaded anywhere?
No, all whitespace processing happens locally in your browser using JavaScript as you type or change the options. Nothing is sent to a server.
What happens with an empty textarea?
The before and after character counts both show 0, and the result area shows a placeholder dash, since there is no text to process.
Can I copy the cleaned result?
Yes, a Copy button appears above the result once there is output, copying the cleaned text to your clipboard.
Also Available As
whitespace remover, remove extra spaces, trim whitespace online, remove blank lines, collapse spaces, strip whitespace tool, clean text spacing
Found a Problem?
Let us know if something with Whitespace Remover isn't working as expected.
Something went wrong. Please try again.
Thanks — we'll take a look.