Skip to content

Remove Extra Spaces From Text

Paste messy text and get it back with one space between words, clean line edges and no stray gaps before commas or full stops.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

Cleanup

Before
84 chars
After
71 chars
Removed
13 chars

Cleaned text

This sentence has too many spaces.\n\n And this line is indented oddly.

Quick answers

How do I remove extra spaces from text?
Paste the text into the box and keep Collapse repeated spaces ticked. Every run of two or more spaces or tabs on a line becomes a single space, and Trim each line strips the spaces at the start and end of each line.
How do I remove double spaces after full stops?
Collapse repeated spaces handles it. "One sentence. Two sentences. Three." comes back as "One sentence. Two sentences. Three." with 2 characters removed. It works the same for triple or longer gaps anywhere in a line.
How do I remove the blank lines between lines of text?
Tick Remove blank lines. Every empty line is deleted, including lines that hold nothing but spaces or tabs, so a double-spaced list becomes a tight one. The option is off by default because blank lines are what separate paragraphs.
Can this tool remove all spaces from text?
No. It always leaves one space between words. To strip every space, use the Find and Replace Text tool on this site: put a single space in Find and leave Replace with empty. That turns "555 123 4567" into "5551234567".
Does removing extra spaces delete my line breaks?
No. Line breaks inside the text are kept, so it has the same lines and paragraphs afterwards. Three things remove one: ticking Remove blank lines, a line that begins with a comma, full stop or similar mark while Fix spaces before punctuation is on, and empty lines at the very start or end of the text.
What counts as an extra space?
Any run of two or more whitespace characters on one line: ordinary spaces, tabs, non-breaking spaces and the wide spaces used in Chinese and Japanese text. Spaces at the start or end of a line and spaces sitting in front of punctuation are also treated as surplus.

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.

OptionOn by defaultWhat it changesBeforeAfter
Convert tabs to spacesYesEach tab character becomes one spaceName[tab]Email[tab][tab]PhoneName·Email·Phone
Collapse repeated spacesYesTwo or more spaces in a row become oneThe··quick···brown····foxThe·quick·brown·fox
Fix spaces before punctuationYesDeletes whitespace in front of , . ; : ! ?Hello·,·world·!·How·are·you·?Hello,·world!·How·are·you?
Trim each lineYesStrips spaces from both ends of every line···Invoice·total:··42.00···Invoice·total:·42.00
Remove blank linesNoDeletes empty and whitespace-only linesFirst line, 2 blank lines, Second lineFirst 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.

  1. Tabs become single spaces, so a tab next to a space turns into two spaces that the next step can merge.
  2. Runs of two or more whitespace characters on a line shrink to one ordinary space. Line breaks are excluded from this step.
  3. Whitespace directly in front of a comma, full stop, semicolon, colon, question mark or exclamation mark is deleted.
  4. Each line loses the spaces at its start and end.
  5. Empty lines are dropped, including lines that only became empty in the previous step.
  6. 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. 1

    Paste your text into the Your text box.

  2. 2

    Leave Collapse repeated spaces and Trim each line ticked to get single spacing and clean line edges.

  3. 3

    Tick Remove blank lines if you also want the empty lines between paragraphs or list items deleted.

  4. 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. 5

    Check the Before, After and Removed counts, then copy the Cleaned text or download it as cleaned.txt.

Frequently asked questions

Why does text copied from a PDF have so many extra spaces?
A PDF stores where each piece of text sits on the page, not a flowing paragraph. Copying it rebuilds the text from those positions, which tends to produce double spaces where a line was justified, indentation at the start of rows and a line break at the end of every printed line.
Can it join lines that were broken in the middle of a sentence?
No. Line breaks are kept exactly where they are, so "The report" on one line and "was filed" on the next stay on two lines. Only blank lines can be removed. Joining wrapped lines into one paragraph needs a find and replace on the line break itself.
Does it remove leading spaces as well as trailing spaces?
Yes. Trim each line strips both ends of every line in one go. There is no separate setting for leading only or trailing only, so indentation you want to keep will be lost unless you untick the option.
Will it break a tab-separated table or CSV?
It can. With the defaults every tab becomes a space, so the column separators in tab-separated data disappear. Untick Convert tabs to spaces and Collapse repeated spaces for that kind of data, and Trim each line too if rows can start or end with an empty cell. In comma-separated files the defaults remove the spaces in front of each comma and collapse repeated spaces inside values.
What does the Removed number tell me?
It is the Before character count minus the After count. Line breaks count as characters, so removing three blank lines adds 3 to the figure. A result of 0 means none of the ticked options found anything to remove.
Is my text uploaded anywhere?
No. The clean-up is done by your browser on your own device. The text is not sent to a server or stored, so contracts, drafts and other private material can be pasted in.
Does it change the spacing inside quotes or code strings?
Yes. The tool does not understand quotes or programming syntax, so repeated spaces inside a quoted string are collapsed like any others. If exact spacing inside part of the text matters, clean the rest separately.

Looking for something else? Browse all text tools or see every tool.