Trim Whitespace

Clean up text by removing unwanted spaces, tabs, and line breaks

Characters:0
Spaces:0
Trim Leading
No text
Trim Trailing
No text
Trim Both Ends
No text
Remove All Spaces
No text
Remove Extra (keep single)
No text
Trim Each Line
No text
Remove Empty Lines
No text

About the Whitespace Trimmer

This tool trims whitespace from text: leading and trailing spaces on every line, plus optional collapsing of repeated spaces inside lines. It is the fix for text pasted out of a PDF, email or web page.

Trim whitespace when text has come from somewhere that added its own. Copying out of a PDF leaves trailing spaces and tabs on every line, email clients add indentation, and web pages contribute non-breaking spaces that look identical to normal ones but behave differently.

Invisible characters cause visible failures. A trailing space breaks an exact-match lookup, makes two identical-looking values compare as different, and turns a clean diff into noise. Deduplication and sorting both misbehave when entries differ only by whitespace.

Trimming line ends is nearly always safe, which is why it is the default. Collapsing internal runs of spaces is offered separately, since it would flatten deliberate indentation in code or formatted output.

How to use the Whitespace Trimmer

  1. Paste your text. Enter the text with unwanted whitespace.
  2. Trim the lines. Leading and trailing whitespace is removed from every line.
  3. Optionally collapse spaces. Turn on collapsing to reduce runs of spaces inside lines to one.
  4. Copy the clean text. Take the trimmed output.

Whitespace Trimmer features

  • Leading and trailing whitespace removed per line
  • Optional collapsing of repeated internal spaces
  • Tabs and non-breaking spaces handled
  • Indentation preserved unless you choose otherwise
  • Instant results as you type
  • Runs entirely in your browser

Frequently asked questions

What exactly gets trimmed?

Leading and trailing spaces, tabs and non-breaking spaces on every line. Internal spaces are only collapsed if you enable that option.

Will it destroy my code indentation?

Only if you enable space collapsing. Line-end trimming alone leaves leading indentation untouched.

Why do trailing spaces matter?

They break exact-match comparisons, make identical-looking values differ, and add noise to diffs and deduplication.

Are non-breaking spaces handled?

Yes. They look like normal spaces but behave differently, and are converted or removed along with regular whitespace.

Is my text uploaded?

No. Trimming runs entirely in your browser.