Whitespace Remover

Clean up messy spacing in seconds. This free whitespace remover can collapse repeated spaces, trim every line, delete empty lines or strip every space and tab, and it works in your browser without uploading your text.

Whitespace RemoverPrivate · runs on your device
Input
Words 0Characters 0Lines 0
Cleaned text

Example: too many spaces → too many spaces

How to use the whitespace remover

The four options are tick boxes, and the result updates as soon as you change one.

  1. Paste the text with irregular spacing into the Input box.
  2. Choose the options in the tick boxes above the output. Collapse repeated spaces and Trim line ends are ticked by default. Remove empty lines and Remove ALL spaces start unticked.
  3. Read the result in the box labelled Cleaned text. Combine options if you need more than one kind of clean-up.
  4. Press Copy, Download .txt or Use as input.

As an example, too many spaces becomes too many spaces with the default options. Processing is local to your browser, so code, data exports and private documents stay on your machine.

What each option does

  • Collapse repeated spaces. Within a line, a run of two or more spaces, tabs or non-breaking spaces becomes a single space. A lone tab is left as it is.
  • Trim line ends. Removes whitespace from the start and the end of every line. Despite the name, this includes leading indentation.
  • Remove empty lines. Deletes lines that are empty or hold only whitespace.
  • Remove ALL spaces. Deletes every space, tab and non-breaking space. Line breaks stay, but runs of them are reduced to one, so blank lines disappear whatever the other boxes say. When it is ticked, the other three options make no further difference.
OptionsResult for the same text
Default (collapse and trim)Name Age, a blank line, Ana 31, two blank lines, Ben 27
Default plus Remove empty linesName Age, Ana 31, Ben 27 on consecutive lines
Remove ALL spaces on +44 20 7946 0958+442079460958

The text in the first two rows was typed with extra spaces around each word, a blank line after the header and two blank lines before the last row. The default options also convert Windows line endings to plain ones.

Where stray whitespace comes from, and who needs it gone

Extra whitespace creeps in from many directions: PDFs add spaces at the start of lines, columns aligned with the space bar leave long runs, spreadsheet exports pad cells, and web pages indent their source with tabs that come along when you copy.

  • Data cleaning. Trailing spaces make apple and apple different values, so lookups and joins fail. Trimming is a standard first step.
  • Codes and numbers. Serial numbers, licence keys, IBANs and phone numbers often arrive with spaces that web forms refuse.
  • Writing. Double spaces after full stops are a typing habit that tidy copy does not need.
  • Developers. Minifying a string or comparing two outputs.

Related tools include the remove line breaks tool for hard returns inside paragraphs and the duplicate line remover for repeated entries.

Cautions and invisible characters

  • Indentation is lost. With Trim line ends ticked, leading spaces go, which breaks Python, YAML and Makefiles. Untick it for code, and avoid Remove ALL spaces.
  • Aligned tables. Collapsing spaces ruins columns lined up with the space bar.
  • Other invisible characters. Zero-width spaces, some typographic spaces and soft hyphens are not touched by the collapse and remove-all options. If spacing still looks wrong afterwards, run the text through the text formatting remover, which deletes zero-width characters and turns non-breaking spaces into ordinary ones.
  • Keep the original. Option changes apply to the text in the Input box, so keep your source there and switch options freely.

Tidying spaces first also makes counts cleaner in the word counter.

Some quick recipes: for prose copied from the web, keep the two default boxes ticked. For a data export with padded cells and gaps, keep the defaults and add Remove empty lines. For a code or serial number that must have no gaps, tick Remove ALL spaces. For source code or any indented format, untick Trim line ends and Collapse repeated spaces so that the structure survives, and use the tool only to remove empty lines.

Quick answers

Frequently asked questions

The questions people ask most, answered in plain words.

How do I remove all spaces from text?

Paste the text into the Input box and tick Remove ALL spaces. Every space, tab and non-breaking space is deleted, so a b c becomes abc. Line breaks stay, but blank lines disappear. Copy the result with the Copy button.

How do I remove double spaces between words?

Tick Collapse repeated spaces, which is on by default. Any run of two or more spaces, tabs or non-breaking spaces within a line becomes one space, while single spaces and line breaks are untouched. It is the quickest fix for double spaces after full stops.

How do I remove blank lines from text?

Tick Remove empty lines. Lines that contain nothing, or only spaces and tabs, are deleted so the remaining lines sit directly under each other. This helps with lists and exported data where blank rows interfere with sorting or importing.

Will the whitespace remover delete my line breaks?

Not the ones between lines of text. The collapse and trim options work inside each line, and Remove empty lines deletes only blank lines. Remove ALL spaces also reduces runs of line breaks to one. To join lines into paragraphs, use the remove line breaks tool.

Why do some spaces remain after cleaning?

They are probably not ordinary spaces. Zero-width spaces and some typographic spaces, such as thin and em spaces, are not removed by this tool. With the default options a single non-breaking space is also kept, unless it sits next to another space. The text formatting remover deletes zero-width characters and converts typographic spaces.