My Tool Studio
Text

Trim Whitespace

Invisible characters break things quietly. A password with a trailing space, a spreadsheet key that won't match because of a leading tab, a YAML file that fails on padding you can't see. This trim whitespace tool strips leading and trailing spaces, tabs, and even non-breaking spaces from every line of your text, while leaving the spacing inside each line alone. It's a whitespace remover with a deliberately light touch: empty lines survive, inner alignment survives, only the invisible padding at the edges goes. When you need to trim spaces from text before a comparison or an import, this beats writing a spreadsheet formula every single time.

Always freeNo sign upRuns in your browser

How to use

01

Paste the padded text

Drop the text into the Input pane. The Try sample button loads a deliberately messy example with leading and trailing spaces so you can see the cleanup in action.

02

Review the trimmed output

Every line comes back with its edges stripped while inner spacing stays untouched. Compare the panes side by side to confirm nothing you care about was removed.

03

Copy the clean version

Grab the result with the copy button on the Output pane and paste it wherever the whitespace was causing trouble. Use Clear to start on the next snippet.

Why Trim Whitespace

Common questions

Does trim whitespace touch the spaces inside a line?
No. Only the run of whitespace at the start and end of each line is stripped. Words keep their internal gaps exactly as written, which protects intentional formatting like aligned columns.
Can this whitespace remover strip non-breaking spaces?
Yes. The trim uses JavaScript's built-in whitespace definition, which includes the non-breaking space, U+00A0, along with tabs and other Unicode spacing characters. Those are the ones that sneak in from Word and web pages and defeat manual deletion.
Why do trailing spaces cause so many bugs?
Because comparisons are exact. The string abc plus an invisible space is different from abc, so lookups miss, logins fail, and CSV imports create duplicate records. Trimming before comparing eliminates the whole bug class.
How do I trim spaces from text on every line at once?
Just paste the whole block. The tool splits your text into lines, trims each one independently, and rejoins them, so a 2,000 line file gets cleaned in a single paste with no per-line effort.
Will trimming whitespace delete my blank lines?
No, empty lines are preserved in place. A blank line becomes a truly empty line, with any stray spaces on it removed, but the line itself stays, so paragraph structure doesn't collapse.
Can I remove extra spaces online without opening Excel or Word?
That's the point of this page. Paste, read, copy, done, with nothing installed and nothing uploaded. It replaces the TRIM formula dance for one-off cleanups.
Does the trim whitespace tool handle tab indentation?
Yes, tabs at the start or end of a line count as whitespace and are removed. Keep that in mind with indented code or Makefiles, where leading tabs are meaningful and shouldn't be stripped.
Is the trimmed output updated live?
It is, the Output pane recalculates on every keystroke. There's no clean button to press, so what you see on the right is always the current trimmed state of the input.

More Text tools

View all