Trim Whitespace

Remove leading and trailing whitespace from text or each line.

Trim spaces and tabs from the start and end of each line, from the whole text only, or from just the start or the end of lines. You can also remove empty lines. It's useful for lists copied from spreadsheets or web pages, where invisible trailing spaces cause mismatches in lookups, comparisons and imports.

Common use cases

  • Clean a list before importing it into a spreadsheet or database
  • Remove indentation from pasted code or text
  • Fix trailing spaces that break VLOOKUP or matching

How to use

  1. Paste the text.
  2. Choose what to trim and whether to remove empty lines.
  3. Copy the result.

FAQ

Why do trailing spaces matter?

To a computer, "apple" and "apple " are different, so invisible spaces make lookups, de-duplication and logins fail.

Is there a spreadsheet formula for this?

TRIM() in Excel and Google Sheets removes spaces at both ends and turns runs of spaces into one.