Skip to content
Case Converter Online
en

Whitespace Remover

Clean up text full of double spaces, empty lines and stray tabs. Pick what to remove and copy the tidy result.

Choose what to clean
Characters
0
Words
0
Lines
0

Runs in your browser. Your text is never uploaded.

What counts as whitespace

Whitespace is any character that shows up as empty space: the normal space, the tab, the line break, and a group of less familiar characters such as the no-break space (U+00A0), the em space (U+2003) and the zero width space (U+200B). They are invisible, so they are easy to miss, but they cause real problems. Double spaces look sloppy in print. Trailing spaces break spreadsheet lookups. A zero width space hidden in a product code makes two codes that look identical fail to match.

This tool finds that whitespace and removes or normalizes it, while leaving your words alone.

How to use the whitespace remover

  1. Paste your text into Your text.
  2. Look at Clean text on the right. It updates as you type or change an option.
  3. Choose what to clean. These options are on by default:
    • Trim line starts and ends removes spaces and tabs at the beginning and end of every line.
    • Double spaces to single turns any run of spaces into one space.
    • Remove blank lines deletes empty lines, including lines that only contain spaces.
    • Fix hidden and odd spaces turns no-break spaces and other wide spaces into normal ones and deletes zero width characters.
  4. These are off by default, for bigger changes:
    • Tabs to spaces replaces each tab with a single space.
    • Remove all line breaks joins every line into one, with a space in between.
    • Remove all spaces deletes every space and tab.
  5. Press Copy or Download.

The note under the tool tells you how many whitespace characters were removed.

Examples

You paste Options You get
Too many spaces here. Default Too many spaces here.
Line one, three empty lines, Line two Default Line one, then Line two on the next line
a b c Remove all spaces abc
one, two and three on separate lines Remove all line breaks one two three
4111 1111 1111 1111 Remove all spaces 4111111111111111
Tabs[tab]and, where [tab] is a tab Tabs to spaces Tabs and

In the first example the tool removed 12 whitespace characters. A line such as “and hidden spaces” copied from a web page might contain a no-break space and a zero width space. Fix hidden and odd spaces turns the first into a normal space and deletes the second, so the words that were glued together by the invisible character end up next to each other, exactly as they appeared on screen.

Why extra whitespace appears

  • Copying from PDFs. PDF text is placed line by line, so copying often brings line breaks and runs of spaces with it. If the problem is mostly line breaks in the middle of sentences, the line break remover is the better fit.
  • Copying from web pages. Many sites use no-break spaces to keep words together, and some insert zero width spaces to allow line wrapping in long words.
  • Typing habits. Two spaces after a full stop is still common. Most style guides now ask for one.
  • Exports from other programs. Spreadsheets and databases often pad values with trailing spaces to a fixed width.
  • Indentation. Text copied from code or emails can come with tabs and leading spaces on every line.

Tips and limits

  • Keep paragraphs but lose the mess. Switch off Remove blank lines if your text uses blank lines between paragraphs. You still get trimmed lines and single spaces.
  • Tables and columns. Text copied from a spreadsheet uses tabs between cells. Leave Tabs to spaces off if you want to paste the result back into a spreadsheet.
  • Code. Indentation matters in Python, YAML and Makefiles. Switch off Trim line starts and ends before cleaning code, or the indentation will be removed.
  • Other symbols. This tool only touches whitespace. To remove punctuation and symbols too, use the special character remover. For fancy fonts and curly quotes, use the plain text converter.

Other ways to remove extra spaces

Microsoft Word. Open Find and Replace (Ctrl+H). Put two spaces in Find what and one space in Replace with, then press Replace All. Repeat until Word reports no more replacements. To remove empty lines, search for ^p^p and replace with ^p.

Google Docs. Open Edit, then Find and replace. Tick Use regular expressions, find {2,} (a space followed by {2,}) and replace it with a single space.

Excel and Google Sheets. =TRIM(A1) removes spaces at both ends and turns runs of spaces inside the text into one. It does not remove no-break spaces. Wrap it like this for text from the web: =TRIM(SUBSTITUTE(A1, CHAR(160), " ")).

Code. In JavaScript, text.replace(/ {2,}/g, ' ').trim() collapses spaces, and text.replace(/\s+/g, '') removes all whitespace. In Python, " ".join(text.split()) collapses every run of whitespace, including line breaks, into a single space.

Whitespace Remover: questions and answers

How do I remove extra spaces from text?

Paste the text into the Your text box. With the default options, spaces at the start and end of each line are trimmed, double spaces become single spaces and blank lines are removed. Copy the result from the Clean text box.

How do I remove all spaces?

Switch on Remove all spaces. Every space and tab disappears, which is handy for card numbers, codes and phone numbers. Line breaks stay unless you also switch on Remove all line breaks.

What are hidden or odd spaces?

Characters that look like a space or like nothing, such as the no-break space (U+00A0) and the zero width space (U+200B). They often come along when you copy from web pages or PDFs. Fix hidden and odd spaces turns the wide ones into normal spaces and deletes the zero width ones.

Will it change the words in my text?

No. Only whitespace is changed: spaces, tabs, line breaks and invisible spacing characters. Letters, numbers and punctuation are left exactly as they are.

More text tools

See all tools