Remove Extra Spaces
Collapse multiple spaces into one and trim leading/trailing whitespace to tidy up messy text.
The three things it fixes
- Runs of spaces inside a line become a single space. Two or more tabs in a row, or a mix of spaces and tabs, also become one space.
- Leading whitespace at the start of every line is removed, so indentation goes.
- Trailing whitespace at the end of every line is removed.
A real run, with the tab shown as [tab]:
| Input line | Output line |
|---|---|
| (2 spaces)Hello(4 spaces)world.(2 spaces) | Hello world. |
| (3 spaces)This[tab]is(3 spaces)a(2 spaces)test. | This[tab]is a test. |
| [tab][tab]Indented line[tab](space) | Indented line |
What it deliberately leaves alone
- A single tab between words stays a tab. Only runs of two or more are collapsed. That keeps tab-separated data copied from a spreadsheet intact, as long as no cell is empty. Two tabs in a row mean an empty cell, and they become one space.
- Blank lines stay. Three empty lines between paragraphs are still three empty lines. Use Remove Empty Lines if you want them gone.
- Line breaks stay. Your lines are cleaned one by one, never joined. Use Text to One Line to flatten them.
- Non-breaking spaces stay. These look like normal spaces but are a different character, common in text copied from web pages and word processors. Two of them in a row are not collapsed.
Two spaces after a full stop
If you learned to type two spaces after every sentence, this converts a whole document to single spaces in one pass. Sentence one. Sentence two. becomes Sentence one. Sentence two.
It also cleans up the double spaces left behind by other tools. Removing punctuation or duplicate words deletes a word or symbol but leaves the spaces on either side of it, so running this afterwards closes the gap.
When not to use it
Indentation is removed from every line, so don't run code through it if the indentation matters. Python and YAML stop working when their leading spaces are removed, and nested Markdown lists lose their nesting. Text laid out in columns with spaces, such as a plain-text table, also falls apart. For those, fix the spacing by hand or use your code editor's formatter.
Frequently asked questions
Why are some double spaces still there?+
They are probably non-breaking spaces, which the tool doesn't treat as ordinary spaces. Use Find and Replace: copy one of the odd spaces from your text into the Find box, type a normal space in the Replace box, then run this tool again.
Will it remove the space between every word?+
No. One space between words is always kept. If you want every space, tab and line break removed, use Remove All Whitespace instead.
Does it change line endings from Windows files?+
The browser converts Windows line endings to plain line feeds when you paste into the box, and the result keeps them that way. Your lines are not merged or reordered.
Embed this tool on your website
Free to use on blogs, school sites and intranets. Paste this code into your page's HTML; please keep the credit line.
<iframe src="https://utilityapp.lat/embed/text/remove-extra-spaces" title="Remove Extra Spaces" width="100%" height="600" style="border:0;max-width:760px" loading="lazy"></iframe> <p style="font-size:13px"><a href="https://utilityapp.lat/text/remove-extra-spaces">Remove Extra Spaces</a> by UtilityApp</p>