How the Remove Extra Spaces works

The tool cleans your text in a fixed order and counts every change it makes. First, if you choose to, it removes zero-width characters: zero-width space (U+200B), zero-width non-joiner (U+200C), zero-width joiner (U+200D) and the byte order mark (U+FEFF). A zero-width joiner between two emoji is kept, because it glues emoji such as a family together. These characters are invisible but break searches, comparisons and spell checkers. Leave the option off for Persian or Indic text, where the joiners change how words are displayed.

Next it converts the non-breaking space (U+00A0), the typographic spaces U+2000 to U+200A, the narrow no-break space (U+202F), the medium mathematical space (U+205F) and the ideographic space (U+3000) to ordinary spaces. Text copied from web pages, PDFs and word processors often contains these, and they look identical to normal spaces.

Then each line is processed: tabs are expanded to spaces at the tab width you chose, spaces at the start and end are trimmed, and runs of two or more spaces or tabs inside the line are replaced with one space. When trimming is off, the indentation at the start of a line is left as it is. Finally, blank lines are kept, reduced to one in a row, or removed.

How to use the Remove Extra Spaces

  1. Paste your text into the Text box, open a text file, or select Load example.
  2. Choose what to clean: collapse repeated spaces and tabs, trim each line, convert non-breaking and other Unicode spaces, remove zero-width characters, what to do with Blank lines and whether to convert Tabs to spaces.
  3. The cleaned text updates as you type. You can also select Clean up text or press Ctrl + Enter.
  4. Review the table of changes, then copy the cleaned text or download it as a .txt file.

Example

This input (with a tab between "tabs" and "and", and a non-breaking space before "here"):

   Too    many     spaces


Extra tabs	and blank lines
Non-breaking space here  

with the default options becomes:

Too many spaces

Extra tabs	and blank lines
Non-breaking space here

The change summary reports 2 runs of spaces collapsed, 2 lines trimmed, 1 blank line removed and 1 Unicode space converted. The single tab is kept because it is not a run; choose a tab width to convert it.

Common use cases

  • Tidying text copied from a PDF, where words are separated by several spaces and paragraphs by many blank lines.
  • Replacing non-breaking spaces from web pages or Word documents that break searches and comparisons.
  • Removing invisible zero-width spaces and byte order marks that cause errors in code, CSV files and configuration values.
  • Converting tab-indented text to spaces before pasting it into a document or form.

Frequently asked questions

Which Unicode spaces are converted?

The non-breaking space (U+00A0), the typographic spaces from U+2000 to U+200A (en space, em space, thin space, hair space and others), the narrow no-break space (U+202F), the medium mathematical space (U+205F) and the ideographic space (U+3000). Each becomes a normal space, and repeated spaces can then be collapsed.

Which zero-width characters are removed?

The zero-width space (U+200B), zero-width non-joiner (U+200C), zero-width joiner (U+200D) and the byte order mark or zero-width no-break space (U+FEFF). A zero-width joiner between two emoji is kept, because it combines them into one emoji such as a family. The option is off by default because the joiners are needed in some languages, such as Persian and Hindi.

Does collapsing spaces remove indentation?

Collapsing only affects runs of two or more spaces or tabs after the first non-space character of a line, so indentation is kept. Tick Trim spaces at the start and end of each line to remove indentation as well.

What is the difference between collapsing and removing blank lines?

Collapse to a single blank line keeps paragraphs separate but replaces several blank lines in a row with one. Remove all blank lines deletes every empty line. Lines that contain only spaces count as blank.

How are tabs converted to spaces?

Each tab is replaced with enough spaces to reach the next tab stop, using the tab width you choose (2, 4 or 8), so columns that were aligned with tabs stay aligned.

Is my text uploaded?

No. The clean-up runs in your browser and your text is not sent to our server.