FormatterHQ

Remove Extra Spaces

Collapse double spaces and tabs into single spaces, trim the start and end of every line, and shrink runs of blank lines.

Input TEXT
Output TEXT
Ready.

How to use the Remove Extra Spaces

  1. Paste text that has uneven spacing.
  2. Choose whether multiple blank lines should be collapsed into a single blank line.
  3. Copy the tidied text.

Remove Extra Spaces Without Losing Line Breaks

Double spaces after periods, tabs from copied tables and indentation from PDFs make text look messy. This tool will remove extra spaces so that words are separated by exactly one space, while your line breaks and paragraphs stay where they are.

What gets cleaned

  • Runs of spaces, tabs and non-breaking spaces inside a line become one ordinary space.
  • Spaces at the start and end of every line are trimmed. Lines that held only spaces become truly empty.
  • With the blank-line option on (the default), three or more line breaks in a row shrink to two, which leaves at most one blank line between paragraphs.

Example

Before:
"  This   sentence    has[tab][tab]too many     spaces.  "
""
""
""
"   And so   does this one."

After:
"This sentence has too many spaces."
""
"And so does this one."

Turn the blank-line option off and all four line breaks between the two sentences are kept; only the spaces are fixed.

Remove extra spaces vs remove all whitespace

This tool keeps a single space between words, so the text stays readable. If you need every space gone, for example to join a hex string or a code that was typed in groups, use Remove Whitespace. If the problem is line breaks in the middle of sentences, Remove Line Breaks is the better fit.

Things to watch out for

  • Indented code. Leading indentation is trimmed, so Python or YAML loses its structure. Use a code formatter for source code instead.
  • Tab-separated data. Tabs become spaces, which merges TSV columns. Convert the data before cleaning it.
  • Invisible characters. Zero-width spaces and soft hyphens are not whitespace, so they are left in place. The Text Cleaner removes those too.
  • Intentional alignment. Text aligned with spaces, such as an ASCII table, will lose its columns.

The same cleanup in spreadsheets and code

Excel and Google Sheets have a built-in TRIM() function that removes leading and trailing spaces and collapses runs of spaces inside a cell. It does not touch non-breaking spaces (CHAR(160)), which often arrive with text copied from web pages, so combine it with a substitution: =TRIM(SUBSTITUTE(A1, CHAR(160), " ")).

In JavaScript, this tool's behavior for one block of text looks roughly like this:

text.split("\n")
    .map(line => line.replace(/[ \t\u00A0]+/g, " ").trim())
    .join("\n")
    .replace(/\n{3,}/g, "\n\n");

In code editors, a regular-expression search for {2,} replaced with a single space fixes double spaces without touching line breaks.

Why double spaces happen

Typewriter habit (two spaces after a period), justified text copied from PDFs, and HTML where several spaces were used for layout are the usual sources. Most style guides today use a single space after a period, and web browsers collapse extra spaces anyway, so extra spaces mostly cause trouble in plain-text fields, databases and word counts.

Privacy

All cleaning happens in your browser; your text is not sent to a server.

Frequently asked questions

How do I replace double spaces with a single space?
Paste the text and the tool replaces every run of spaces or tabs with one space. It also trims spaces from the start and end of each line, so no manual find-and-replace is needed.
Does it remove line breaks too?
No. Line breaks are kept. Only runs of three or more line breaks are shortened to one blank line, and you can switch that off to keep every line break exactly as it was.
Are tabs converted to spaces?
Yes. Tabs and non-breaking spaces inside a line are treated like spaces and collapsed into a single normal space, and tabs at the start of a line are removed.
Why are some odd gaps still in my text?
The gap may come from characters that are not whitespace, such as zero-width spaces, or from special spacing characters inside words. A general text cleaner that strips invisible characters will remove them.

Last updated September 26, 2026

Related tools