Menu

Remove Extra Spaces

Paste your text to turn every run of spaces into a single space, trim the start and end of each line and replace tabs and non-breaking spaces, without touching your line breaks.

0 words 0 characters 0 lines

Continue with this text: Remove line breaksRemove empty linesInvisible characters

Your text stays in your browser: nothing is uploaded or stored on a server.

How to use it

  1. Paste your text into the box, or use Open file for a .txt, .csv or similar plain-text file. Example loads a sample.
  2. The result updates as you type. Three options are on by default: trimming lines, replacing tabs and replacing odd spaces.
  3. Tick Remove spaces before punctuation if the text has gaps such as word , or ( note ).
  4. Click Copy, or Download .txt. Use as input moves the result into the box so you can run another cleanup on it, such as removing empty lines.

What each option does

Collapsing spaces is always on: any run of two or more ordinary spaces becomes one space. The options decide what else counts as a space and how line edges are treated.

Option Default What it changes
Trim spaces at the start and end of lines On Removes all spaces at the beginning and end of every line, not only the first and last line of the text. Also turns Windows line endings (\r\n) into \n.
Replace tabs with a space On Each run of tabs becomes one space, which is then merged with any spaces next to it.
Turn non-breaking and other odd spaces into normal spaces On Converts the no-break space (U+00A0), the typographic spaces U+2000 to U+200A (en space, em space, thin space, hair space and others), the narrow no-break space (U+202F), the medium mathematical space (U+205F) and the ideographic space (U+3000).
Remove spaces before punctuation Off Deletes spaces before , . ; : ! ? % ) ] } when the mark is followed by a space, a line end, a closing quote or another such mark, and deletes spaces after ( [ {.

The rules, exactly

The steps run in this order: odd spaces become normal spaces, tabs become spaces, runs of spaces collapse to one, spaces before punctuation are removed, then each line is trimmed. Because of that order, a mix such as a tab followed by a space ends up as one space, not two.

  • Line breaks are never touched. Each line is cleaned on its own, and empty lines stay. A line made only of spaces becomes empty when trimming is on, or a single space when it is off.
  • Trimming off still collapses. With trimming unticked, leading spaces are kept but reduced to one, so more indented becomes more indented.
  • Tabs off keeps tabs as they are. Name⇥Email⇥Phone stays tab-separated, which is what you want for data you will paste back into a spreadsheet. A space next to a tab is not merged with it in that case.
  • Odd spaces off keeps them as they are. Two no-break spaces in a row are not collapsed, because only the ordinary space (U+0020) is counted in a run. Trimming then removes only ordinary spaces and tabs at line ends, so a no-break space or a byte order mark (U+FEFF) at the start or end of a line stays.
  • Zero-width characters are not removed. The zero-width space (U+200B) and joiners have no width and are not spaces to this tool. The invisible characters remover handles them.
  • Letters, accents, emoji and other scripts pass through unchanged. Café 👍🏽 naïve becomes Café 👍🏽 naïve.
  • No spaces are added. The punctuation option removes a space before a comma but never inserts one after it, so word,next stays as it is.

The punctuation option only removes a space when the mark ends a word: it must be followed by a space, the end of the line, a closing quote (" ' ” ’ ») or another punctuation mark. A period that starts a word keeps its space, so Use the .NET SDK and save as file .txt and Version .5 is out stay unchanged, while He said "no" . becomes He said "no".. Code is still affected: x = a ? b : c becomes x = a? b: c. Leave the option off for code and for French text, where a space before ! or ? is correct.

Worked examples

The Example button loads this text, with a tab and spaces at the start of the second line and two spaces at the end:

This   sentence  has    too many spaces .
	  Tabs and   leading spaces   too  !  

With the default options:

This sentence has too many spaces .
Tabs and leading spaces too !

With Remove spaces before punctuation also ticked:

This sentence has too many spaces.
Tabs and leading spaces too!

More results from the default settings, plus the punctuation option where noted:

Before After
End of sentence. Next one. End of sentence. Next one.
Price: + 2 no-break spaces + 10 USD Price: 10 USD
Name⇥Email⇥Phone (tabs) Name Email Phone
John Smith , Sales Manager (punctuation on) John Smith, Sales Manager
Hello , world ! Is it 50 % off ( or not ) ? (punctuation on) Hello, world! Is it 50% off (or not)?
Wait . . . what (punctuation on) Wait... what

When people need it

  • Text copied from a PDF or a web page. PDF text can arrive with several spaces between words, and web pages use non-breaking spaces ( ) that look like spaces but break search and replace. If the PDF also split sentences across lines, follow up with Remove line breaks or read how to remove line breaks from PDF text.
  • Lists exported from a CRM or spreadsheet. Names such as John Smith with a trailing space fail to match John Smith when you deduplicate or look them up. Clean them here, then use Remove duplicate lines.
  • Old documents typed with two spaces after each period, or text pasted between programs that adds tabs.
  • Social posts, meta descriptions and form fields with a character limit, where stray spaces count against the limit. Check the length afterwards with the character counter.
  • Text with odd gaps you cannot see. If spaces still look wrong after cleaning, the guide to zero-width spaces and invisible characters explains what may be hiding.

Excel TRIM, Word and this tool

Excel’s TRIM function “removes all spaces from text except for single spaces between words”, according to Microsoft. It was designed for the ordinary space (character 32), and Microsoft notes that TRIM alone does not remove the non-breaking space (character 160) common in text copied from the web. That is why a cell can still look padded after =TRIM(A1). With the default options this tool gives the same result as TRIM for ordinary spaces, also converts non-breaking spaces and tabs, and works on a whole column at once: paste the column, clean it, and paste it back. Untick Replace tabs with a space first if you are cleaning several columns copied together, so the tabs that separate them are kept.

In Word or Google Docs you can search for two spaces and replace them with one, repeating until nothing is found. That works for ordinary spaces but misses tabs and non-breaking spaces unless you search for them separately; pasting the text here handles all of them in one step.

Questions

How do I remove double spaces between words?

Paste the text in the box. Every run of two or more spaces becomes one space as you type, with no option to set. Copy the result or use Download .txt.

Does it remove the two spaces after a period?

Yes. "End of sentence. Next one." becomes "End of sentence. Next one." The tool does not treat spaces after a period differently from any other spaces.

Will it join my lines or delete empty lines?

No. Line breaks are never removed, and empty lines stay where they are. A line that holds only spaces becomes an empty line. To join lines use Remove line breaks; to delete blank lines use Remove empty lines.

Why do some spaces stay after cleaning?

The text probably contains a character this tool does not change, such as a zero-width space (U+200B) or another invisible character. Run it through Remove invisible characters, which lists what it finds.

Is this the same as the TRIM function in Excel?

With the default options, yes for ordinary spaces, and it goes further. Excel's TRIM keeps single spaces between words and removes the rest, but Microsoft notes it does not remove the non-breaking space (character 160) on its own. This tool turns non-breaking spaces into normal spaces first, then collapses them.

Can I keep the indentation at the start of lines?

Untick "Trim spaces at the start and end of lines". The tool still collapses runs of spaces, so a 4-space indent becomes 1 space. To keep tab indentation exactly, also untick "Replace tabs with a space".

Is my text uploaded anywhere?

No. The cleaning runs in your browser and the text is not sent to a server.