Remove Extra Spaces and Blank Lines

Paste your text to trim lines, collapse double spaces, drop blank lines and replace non-breaking spaces. It all runs in your browser.

Paste your text

Spaces inside lines
Start and end of lines
Blank lines and line breaks

How to remove extra spaces and blank lines

  1. Paste your text into Text to clean. A sample is already there, so a result shows straight away.
  2. Under Spaces inside lines, keep Collapse multiple spaces into one ticked. Tick Convert tabs to spaces if tabs separate your words.
  3. Under Start and end of lines, choose whether to strip spaces at the start (which removes indentation) and at the end of every line.
  4. Under Blank lines and line breaks, collapse runs of blank lines to keep paragraphs, remove them all to close every gap, or tick Join everything into one line to remove all line breaks.
  5. Choose LF or CRLF line endings, then press Copy cleaned text or Download .txt.

What the cleaner does, in order

First it removes invisible characters (zero-width space U+200B, word joiner U+2060, byte order mark U+FEFF, soft hyphen U+00AD) and turns special spaces such as the no-break space (U+00A0) and the ideographic space (U+3000) into ordinary spaces. Text pasted from web pages, Word and PDFs is full of them, and they defeat a plain search for two spaces. The space separators come from the Unicode White_Space property. The zero-width joiner and non-joiner are left alone, because emoji sequences and Persian or Hindi text need them.

Next it splits the text into lines, trims each line, collapses runs of spaces, and handles blank lines last. A line holding only spaces or tabs counts as blank.

Worked example with the default options

The sample text is 63 characters on 6 lines:

  Hello   World

This  has   extra    spaces


And blank lines.

The tool reports 63 characters on 6 lines became 52 characters on 5 lines (11 characters removed), and each stretch of empty lines shrinks to one:

Hello World

This has extra spaces

And blank lines.

Limits and edge cases

Frequently asked questions

How do I remove double spaces from text?

Keep Collapse multiple spaces into one ticked. Every run of two or more spaces becomes a single space. Text from websites and PDFs often hides non-breaking spaces, so also keep the special spaces option ticked.

How do I remove blank lines but keep my paragraphs?

Set Blank lines to Collapse runs of blank lines to one. Paragraphs stay separated by a single empty line while stacks of empty lines shrink. Choose Remove all blank lines only when you want no gaps at all.

How do I remove non-breaking spaces copied from a website?

Keep Turn non-breaking and other special spaces into normal spaces ticked. It converts U+00A0 and the other Unicode space separators to ordinary spaces, and zero-width spaces are removed by the invisible characters option.

Does it keep code indentation?

Yes, if you untick Remove spaces at the start of each line. Indentation stays exactly as typed and only repeated spaces after the first character are collapsed. Untick Collapse multiple spaces into one as well to leave every space alone.

What is the difference between CRLF and LF line endings?

Windows has traditionally ended each line with two characters, CR and LF, while macOS and Linux use LF alone. Mixed endings can show up as stray ^M characters in scripts and diffs. Pick the style you need under Line endings in the result and use Download .txt to keep it exactly.

Sources: Unicode Character Database, PropList.txt; Unicode Standard Annex #44; MDN, CRLF.