About the Remove Extra Spaces
Remove extra spaces from text in one step: double and triple spaces, tabs, non-breaking spaces and every line break are all reduced to a single space, and the spaces at the very start and end are trimmed off. Run text through it after copying it from a PDF, a spreadsheet cell, a web page or a form, before you reuse it.
The cleaned text appears as you paste, with a Copy button beside it. Because the clean-up runs in your browser, you can safely tidy names, addresses or customer notes.
How the whitespace remover works
The tool looks for every run of whitespace characters, however long, and replaces the whole run with one ordinary space. A run can mix characters: two spaces, a tab and another space count as one run and become one space.
"Whitespace" here means the full set JavaScript recognises: normal spaces, tabs, line feeds and carriage returns, the non-breaking space that word processors and web pages insert (often shown as ), the wide spaces used in typesetting and the full-width ideographic space. After that, the text is trimmed so it doesn't begin or end with a space.
The part that catches people out: line breaks are whitespace too, so paragraphs and lists are joined into a single line. That is ideal for a spreadsheet cell or a one-line field, but if you need to keep the line structure, clean each line separately or use the dedicated line-break tools instead.
output = input.replace(/\s+/g, " ").trim()
Assumptions and limits
- Line breaks are removed along with the extra spaces, so multi-line text comes out as one line.
- Zero-width spaces (U+200B) are not whitespace to this tool and stay in the text, invisible. They can still break searches or matching.
- A single space before punctuation is not touched: "Hello , world" stays as it is. Only runs of two or more spaces shrink.
- Spaces inside words can't be told apart from spaces between words, so a word split as "infor mation" remains split.
- Indentation in code or poetry is lost; don't use it on Python, YAML or anything where leading spaces carry meaning.
Worked examples
Clean spaces in text copied from a PDF
Text copied out of a PDF often arrives with double spaces after full stops, a tab where a column was and a line break mid-sentence. All of it becomes single spaces.
" Hello world,\tthis is\n\nmessy text. " → "Hello world, this is messy text."
Trim spaces in a pasted price
A price copied from a web page can carry non-breaking spaces that look normal but stop a spreadsheet formula or a search from matching. "Price: Rs 500" built with three non-breaking spaces comes out as "Price: Rs 500" with plain spaces.
Prepare a list for one cell
Five names on five lines, some with trailing spaces, become one line of names separated by single spaces, ready to paste into a single spreadsheet cell or a tag field.
Which whitespace characters are cleaned
| Character | Where it comes from | Result |
|---|---|---|
| Repeated normal spaces | Typing, justified text, PDF copy | One space |
| Tab | Spreadsheets, code, tables | One space |
| Line break (LF or CRLF) | Enter key, PDF line wrapping | One space |
| Non-breaking space (U+00A0) | Web pages, Word documents | One plain space |
| Ideographic space (U+3000) | Chinese and Japanese text | One plain space |
| Leading and trailing spaces | Copying whole cells or lines | Removed |
| Zero-width space (U+200B) | Some websites and apps | Kept |
How to use the Remove Extra Spaces
- Paste the messy text. Drop it into the Input Text box over the sample sentence; the word and character counts update underneath.
- Check the cleaned version. The Result box shows the text with single spaces as soon as you paste. Look for paragraphs that have been joined, since line breaks are removed as well.
- Copy the clean text. Click Copy and drop it into your document, sheet or form. Use Clear to empty the box before the next piece.
Frequently asked questions
How do I remove double spaces from text?
Paste it into the Input Text box. Each double, triple or longer run of spaces shrinks to one space straight away, and the Copy button takes the cleaned result. There is nothing to configure.
Does it remove spaces between words?
No. Words keep one space between them; only the surplus is removed. If two words were joined by five spaces and a tab, they end up separated by exactly one space.
Why did my paragraphs turn into one line?
Because line breaks count as whitespace, they are collapsed to a space like everything else. To keep paragraphs, clean each paragraph on its own, or use Remove Line Breaks when joining lines is what you actually want.
Can it trim spaces at the start and end of text?
Yes. After the runs of whitespace are reduced, the whole text is trimmed, so there is no space before the first word or after the last one. This also fixes cells that won't match because of a hidden trailing space.
Will it remove non-breaking spaces from Word or HTML?
Yes, the non-breaking space character (U+00A0) is treated as whitespace and replaced with a normal space. The literal text written as HTML code is not converted, because that is five ordinary characters.
Is there a limit on how much text I can clean?
No, the tool sets none. It runs in your browser, so the practical limit is your device's memory and speed. Long documents are fine; very large pastes may take a moment to appear, because the result updates on every change.
This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.