Trim text

Trim whitespace from text: spaces at line starts and ends, double spaces, tabs, non-breaking and zero-width spaces. Optionally shorten to N characters or words.

Your text is processed in your browser and never sent to our server.

0 characters · 0 words · 0 lines

How to trim text online

This tool removes unwanted whitespace from any text: spaces at the start and end of lines, double spaces between words, tabs and invisible characters copied from websites, PDFs or spreadsheets. The result updates as you type.

  1. Paste or type your text into the left box (or open a .txt file).
  2. Choose which whitespace to remove – the defaults fit most cases.
  3. Copy the cleaned text, download it, or send it to another tool.
  • Trim line starts / ends – removes spaces and tabs at the beginning or end of every line. Turn off “Trim line starts” to keep indentation.
  • Collapse multiple spaces – turns runs of spaces into a single space.
  • Fix non-breaking & zero-width spaces – replaces non-breaking spaces ( ), narrow and ideographic spaces with a normal space and deletes zero-width spaces, BOM and soft hyphens.
  • Tabs – replace tabs with a space, remove them, or keep them.
  • Trim whole text – removes empty lines and spaces at the very beginning and end.
  • Remove empty lines – deletes blank lines everywhere.
  • Shorten text – cuts the text to a maximum number of characters or words, optionally with “…”. In character mode the ellipsis counts towards the limit, so the result never exceeds it.

Example

Text copied from a PDF often contains broken spacing. With the default settings this input:

   Invoice   number:	 2026/114   
   Customer:   Ján   Novák     

becomes:

Invoice number: 2026/114
Customer: Ján Novák

Need a meta description or a social media post that fits a limit? Choose Shorten text → to N characters, set 160 and keep “Don't cut words” on – the text ends at the last full word followed by “…”.

Frequently asked questions

How do I trim spaces in Excel or Google Sheets?

Use =TRIM(A1). It removes leading and trailing spaces and collapses double spaces, but it does not remove non-breaking spaces (character 160). For those use =TRIM(SUBSTITUTE(A1, CHAR(160), " ")). Or paste the whole column here and copy it back.

Why does my text still look like it has a space I can't delete?

It is probably an invisible character such as a non-breaking space or a zero-width space. Keep “Fix non-breaking & zero-width spaces” on and they are replaced or removed. Zero-width joiners are kept on purpose, because emoji like 👨‍👩‍👧 depend on them.

Can I keep indentation, for example in code?

Yes. Turn off “Trim line starts” and “Collapse multiple spaces” and set Tabs to “keep”. Only trailing spaces will be removed.

Is my text safe?

Yes. Everything is processed locally in your browser with JavaScript. Your text is never sent to our server.

How do I remove all spaces or empty lines?

To delete every space (not just extra ones) use the spaces remover. For blank lines only there is the empty lines remover, and to change words or characters use find and replace.