Trim Lines

Remove leading and trailing whitespace from every line, keeping internal spacing and line breaks.

Text
Trimmed
Runs locally in your browser

About the Trim Lines

Whitespace at the ends of a line is invisible and expensive. A trailing space on a licence key makes it invalid, a padded value fails a lookup that would otherwise match, and two files that look identical produce a diff full of phantom changes. This tool trims both ends of every line and changes nothing else: the spacing inside each line and the breaks between lines stay exactly as they are.

Trimming follows the full Unicode whitespace definition, so tabs, non-breaking spaces, narrow no-break spaces and the ideographic space are stripped from the ends along with ordinary spaces. Carriage returns from Windows line endings go too, which helps when a file has travelled between operating systems and left a stray \r hanging off each line. Zero-width characters are formatting marks rather than whitespace, so those stay and need a different fix.

A line made entirely of spaces becomes empty but is still a line, so the shape of a list is unchanged; follow with Remove Empty Lines when you want it gone. This is the safe first step before a comparison in the Diff Checker, and Remove Extra Spaces is the stronger version that also squeezes the runs inside each line.

How to use

  1. Paste the text.
  2. Copy the trimmed result.
  3. Internal spacing and line breaks are preserved.

Common questions

Does it change spacing inside a line?
No. Only the start and end of each line are trimmed.
Are blank lines removed?
A line of only spaces becomes empty but is kept. Use Remove Empty Lines to drop it.
Does it remove tabs?
Leading and trailing tabs are trimmed along with spaces.