Whitespace Remover: Remove Extra Spaces and Blank Lines
FREEBy TheToolsBank Editorial TeamLast updated:
How the Whitespace Remover works
Paste your text, choose which cleanup options to apply, and select "Clean Text." The result shows the character count before and after, so you can see exactly how much was removed.
Why pasted text often has extra whitespace
Text copied from PDFs, web pages, or emails frequently carries extra spaces, tabs, or blank lines from the original formatting — this tool strips that out without altering the actual words.
What each option does
| Option | Before | After |
|---|---|---|
| Collapse multiple spaces | Hello···world (3 spaces) | Hello world |
| Collapse tabs | Tabbed→line (a tab) | Tabbed line |
| Trim each line | ··Hello world·· | Hello world |
| Remove empty lines | Lines separated by blank lines | One line after another |
Keep Remove empty lines off if the blank lines separate paragraphs you want to keep.
Where extra whitespace comes from
- PDFs: copied text often has a line break at the end of every line, plus double spaces from justified text.
- Web pages and Word documents: they can contain non-breaking spaces, which look like normal spaces but aren’t. If double spaces remain after cleaning, see the tip below.
- Spreadsheets and CSV exports: a single trailing space (“London “) makes values that look the same fail to match in lookups, filters and duplicate checks.
- Emails and chat apps: extra indentation and blank lines from quoted replies.
Removing whitespace in Excel and Google Sheets
=TRIM(A1)removes spaces at the start and end and turns repeated spaces into one. It works the same in Excel and Google Sheets.- Excel’s TRIM doesn’t remove non-breaking spaces (character 160), which are common in data copied from websites. Use
=TRIM(SUBSTITUTE(A1,CHAR(160)," "))instead. - To remove every space, for example in phone numbers or codes:
=SUBSTITUTE(A1," ","").
Removing whitespace in code
- Python:
text.strip()trims both ends;" ".join(text.split())collapses all whitespace (including tabs and line breaks) into single spaces. - JavaScript:
text.trim()trims both ends;text.replace(/\s+/g, " ").trim()collapses all whitespace. - Remove all spaces:
text.replace(/\s+/g, "")in JavaScript, or"".join(text.split())in Python.
Need to remove repeated lines too? Use Remove Duplicate Lines. Counting what's left? Try the Word Counter or the Character Counter.
Common Mistakes to Avoid
Removing empty lines that were intentional paragraph breaks
Solution:
Not collapsing multiple spaces from justified text
Solution:
Assuming whitespace removal changes word content
Solution:
Frequently Asked Questions
Use the Find & Replace tool: switch on regular expressions, find \s+ and leave the replacement empty. That removes every space, tab and line break, which is useful for phone numbers, codes and account numbers.
Use =TRIM(A1), which removes leading and trailing spaces and turns double spaces into single ones. If spaces remain (common with data copied from websites), use =TRIM(SUBSTITUTE(A1,CHAR(160),” “)) to also remove non-breaking spaces.
Text copied from web pages, Word or PDFs can contain non-breaking spaces, which look like normal spaces but are a different character. To clean them now, use the Find & Replace tool with regular expressions on: find \s+ and replace with a single space.

