How Remove Extra Spaces works
This tool takes text with double spaces, tabs, ragged indentation or empty lines and returns a clean copy. Five checkboxes control it: Collapse repeated spaces, Trim each line, Remove blank lines, Convert tabs to spaces and Fix spaces before punctuation. Four are on by default, so pasting is usually enough. Line breaks are kept, which means paragraphs and lists keep their shape, and blank lines only go when you tick Remove blank lines. It thins spacing rather than deleting it: one space always stays between words. A Before, After and Removed character count shows how much was taken out.
What each of the five options does
In the examples a middle dot (·) stands for one space so the gaps are visible. The After column is the result with the default options, plus Remove blank lines for the last row. The options run in the order listed.
| Option | On by default | What it changes | Before | After |
|---|---|---|---|---|
| Convert tabs to spaces | Yes | Each tab character becomes one space | Name[tab]Email[tab][tab]Phone | Name·Email·Phone |
| Collapse repeated spaces | Yes | Two or more spaces in a row become one | The··quick···brown····fox | The·quick·brown·fox |
| Fix spaces before punctuation | Yes | Deletes whitespace in front of , . ; : ! ? | Hello·,·world·!·How·are·you·? | Hello,·world!·How·are·you? |
| Trim each line | Yes | Strips spaces from both ends of every line | ···Invoice·total:··42.00··· | Invoice·total:·42.00 |
| Remove blank lines | No | Deletes empty and whitespace-only lines | First line, 2 blank lines, Second line | First line, Second line |
Whatever is ticked, the result is also trimmed at the very start and very end of the whole text.
Worked examples with character counts
Each result is the tool's real output with the default options unless stated. A middle dot marks a space.
Double and triple spaces between words
The··quick···brown····fox
The quick brown fox. Before 25 chars, After 19 chars, Removed 6 chars.
A padded line with a gap inside it
···Invoice·total:··42.00···
Invoice total: 42.00. Before 27 chars, After 20 chars, Removed 7 chars.
Spaces left before punctuation
Paris·,··France·;··Rome·,··Italy
Paris, France; Rome, Italy. Before 32 chars, After 26 chars, Removed 6 chars.
A pasted email with tabs and blank lines, Remove blank lines ticked
Dear···Sam·, then 2 blank lines, then ···Thanks·for·the[tab]update·.···, a blank line, Best·, and Alex
Four tight lines: Dear Sam, / Thanks for the update. / Best, / Alex. Before 57 chars, After 43 chars, Removed 14 chars.
With Remove blank lines left off the same text comes back at 46 characters, keeping its three blank lines.
Indented code with Trim each line on
····if·(ready)·{ then ········start(); then ····} on three lines
if (ready) { / start(); / } with every line at the left margin. Before 39 chars, After 23 chars, Removed 16 chars.
Indentation is whitespace too. For code, untick Trim each line and Collapse repeated spaces, or skip this tool.
The order the clean-up runs in, and why it matters
The ticked options are always applied in this sequence, whatever order you tick them in.
- Tabs become single spaces, so a tab next to a space turns into two spaces that the next step can merge.
- Runs of two or more whitespace characters on a line shrink to one ordinary space. Line breaks are excluded from this step.
- Whitespace directly in front of a comma, full stop, semicolon, colon, question mark or exclamation mark is deleted.
- Each line loses the spaces at its start and end.
- Empty lines are dropped, including lines that only became empty in the previous step.
- The whole result is trimmed once more at both ends.
Cases where the result may surprise you
- With Convert tabs to spaces off but Collapse repeated spaces on, a single tab is kept while two tabs in a row still merge into one space.
- Fix spaces before punctuation also acts across a line break. A line that starts with a comma is pulled up onto the line above.
- The punctuation rule cannot tell prose from other text. "Open the .env file :)" becomes "Open the.env file:)". Untick it for filenames, emoticons and code.
- One non-breaking space on its own is left alone. Two or more in a row are replaced by one ordinary space.
- The zero-width space pasted from some web pages does not count as whitespace and is not removed.
- Spacing after punctuation is not added. "Hello,world" stays as it is.
- Brackets and quotes are not in the punctuation list, so "( approx )" keeps its inner spaces.
Removing extra spaces in Word, Excel and Google Sheets
For a one-off paste this page is quickest, but the same clean-up exists inside the programs you may already have open.
In Excel and Google Sheets, =TRIM(A1) strips the spaces at both ends of a cell and reduces every run of spaces inside it to one. Excel's TRIM only recognises the ordinary space, so text copied from a web page that carries non-breaking spaces needs =TRIM(SUBSTITUTE(A1,CHAR(160)," ")).
In Word and Google Docs, open Find and Replace, type two spaces in the find box and one space in the replace box, and choose Replace All. Repeat until it reports no replacements, because each pass only halves a long run.
Neither route deals with blank lines, tabs and punctuation gaps in the same pass, which is where pasting the text here saves time.
Using Remove Extra Spaces
- 1
Paste your text into the Your text box.
- 2
Leave Collapse repeated spaces and Trim each line ticked to get single spacing and clean line edges.
- 3
Tick Remove blank lines if you also want the empty lines between paragraphs or list items deleted.
- 4
Untick Convert tabs to spaces or Fix spaces before punctuation when the text is code, a tab-separated table or anything where those characters matter.
- 5
Check the Before, After and Removed counts, then copy the Cleaned text or download it as cleaned.txt.