Remove Extra Spaces
TX-11Paste text and every run of spaces and tabs inside a line becomes a single space. Spaces at the ends of lines are trimmed, and you can keep indentation in place.
Runs in your browser. Nothing is uploaded.
Text
Result
How to use it
- Paste your text into the input box, or open a text file and drop it on the box.
- Leave Trim the start and end of each line ticked to remove leading and trailing spaces.
- Tick Keep indentation at the start of lines if the text is code or an indented list.
- Press Remove extra spaces. The result updates as you type.
- Copy the cleaned text or download it as a .txt file.
What gets collapsed
Every run of spaces and tabs inside a line becomes one space. A single tab counts as a run, so tab-separated columns turn into space-separated text. If you need the tabs kept, this is not the right tool. Only the ordinary space and the tab are handled: non-breaking spaces, full-width spaces and other special space characters are left exactly as they are, and so is anything that is not a space.
Trimming and indentation
With Trim on, spaces at the end of each line are removed, and spaces at the start too. With Keep indentation on, the leading spaces and tabs of each line are left exactly as typed and only the text after them is collapsed, which keeps code or nested lists lined up. A line made only of spaces becomes an empty line when Trim is on. With Trim off and indentation not kept, a leading run is shortened to a single space.
What it leaves alone
No line breaks are added or removed, so the number of lines stays the same. To delete empty lines use Remove Empty Lines, and to join lines use Remove Line Breaks. Windows (CRLF) and Unix (LF) line endings are kept. Text inside quotes or code is treated like any other text, so do not run this over code where the exact spacing inside strings matters.
Questions people ask
How do I remove extra spaces between words?
Paste your text and press Remove extra spaces. Any run of two or more spaces or tabs inside a line becomes a single space. Spaces at the start and end of each line are trimmed as well, unless you turn Trim off.
How do I remove spaces at the end of lines?
Leave Trim the start and end of each line ticked. It deletes trailing spaces and tabs on every line. To keep the start of the lines as they are, tick Keep indentation at the start of lines too.
Can it keep the indentation of code?
Yes. Tick Keep indentation at the start of lines and the leading spaces and tabs stay exactly as typed. Only the spaces inside the line after the indentation are collapsed. Be careful with code that has aligned columns or spaces inside strings, since those are collapsed too.
Does it turn tabs into spaces?
Yes: any run of spaces and tabs, even one tab on its own, becomes one space, apart from leading indentation when you keep it. If you need tab-separated values left alone, do not use this tool on that text.
Does it remove non-breaking spaces?
No. It only changes the ordinary space and the tab. A non-breaking space (U+00A0), which often arrives when you paste from a web page, is a different character and is left alone, so it can still look like a stray space afterwards.
Will it change the number of lines?
No. It never joins or removes lines. A line that holds only spaces becomes an empty line when Trim is on, but it is still a line. Use the Remove Empty Lines tool afterwards if you want those gone.
About this tool
Every run of spaces and tabs inside a line becomes a single space, and that includes a single tab, so tab-separated data turns into space-separated text. With Trim on, spaces are removed from the end of each line, and from the start too unless Keep indentation is on; with indentation kept, the leading spaces and tabs are left exactly as typed and only the text after them is collapsed. With Trim on, a line that has only spaces becomes an empty line; with Trim off it keeps a single space. Only the ordinary space and the tab are touched. Non-breaking spaces, full-width spaces and other special space characters are left alone. Line breaks are never added or removed, and CRLF or LF endings are kept.