Remove Extra Spaces

Normalise stray whitespace in pasted text — repeated spaces, tabs, blank lines and characters you cannot see.

Runs on your deviceTextWorkingNo account needed

What this tool does

Remove Extra Spaces applies a fixed sequence of whitespace rules to pasted text and does nothing else to it. There is no parsing, no reflowing and no correcting of your wording: every line stays in the same order and no line is ever joined to the one below it. The only lines it can take away are blank ones — empty, or holding nothing but spaces and tabs — and inside a line it only ever adds or deletes spacing and invisible formatting characters, never a letter or a digit.

Each rule is a separate switch. Collapse repeated spaces turns any run of two or more spaces or tabs into a single space. Trim spaces at the start and end of each line strips leading and trailing spaces and tabs from every line, indentation included. Blank lines can be left as they are, capped at one in a row, or removed completely. Tabs can be left alone, expanded to between one and twelve spaces, or deleted. Normalising unusual spaces converts the no-break space, the narrow and medium spaces, the ideographic and Ogham spaces and the en-quad-to-hair-space range into ordinary spaces, then deletes zero-width spaces, zero-width joiners, the word joiner, a byte-order mark and soft hyphens.

Fix spacing around punctuation is the one rule that guesses, which is why it is switched off until you ask for it. It removes a space sitting before a comma, full stop, semicolon, colon, question mark, exclamation mark, per cent sign or closing round or square bracket, removes a space just after an opening round or square bracket, adds a single space after a comma, semicolon or colon unless a digit or a slash follows, and adds a space between a sentence-ending mark and the capital letter after it whenever a lowercase letter or a digit sits immediately before that mark. Curly braces are not in that list and are left alone. Web addresses, www-prefixed hosts and email addresses are lifted out before those rules run and put back afterwards so they survive intact. Nothing else is shielded: a bare filename written as report.PDF comes back as report. PDF, and a path such as /var/log/App.Log is split the same way, because the rule cannot tell either from a missing space between two sentences.

The structural limits are worth knowing before you paste. Collapsing and trimming both destroy indentation, so this is the wrong tool for source code, YAML or Python, and a tab-separated table loses its columns wherever two or more tabs sit next to each other. Deleting the zero-width characters is not always harmless either: a multi-person emoji held together by joiners falls apart into its separate figures, and Persian, Arabic or Indic text loses the non-joiner that keeps neighbouring letters from fusing, so that switch belongs off for writing of those kinds. Windows and classic-Mac line endings are converted to plain newlines on the way in, and whatever the settings say, the output always has its leading empty lines and all of its trailing whitespace removed. Other control codes and the Unicode line separators are not in the list above and pass through untouched. All of this happens in this browser tab — the text is not uploaded, and the tool keeps working with the network off — which is also why it is a paste-in, copy-out tool with no file picker and no download.

How to use it

  1. Paste the untidy text. Drop it into the input box, or press Load sample for a short example carrying double spaces, tabs, trailing spaces and a run of blank lines.
  2. Check the defaults before you run. Collapse repeated spaces, trim line ends and normalise unusual spaces start switched on, and blank lines start capped at one in a row. Tabs start left alone and the punctuation fix starts off. Turn off trimming when the indentation in your text means something.
  3. Decide what tabs become. Leave them, convert each one to a set number of spaces, or delete them. The spaces-per-tab box only appears once you choose to convert.
  4. Run it, then copy the result. The tidied text appears on the right and the summary line counts the characters of stray whitespace removed. The Copy output button hands that version straight to the clipboard.

Processing & privacy

Runs on your device. Your file is processed directly in this browser.

Common use cases

Text copied out of a web page

An HTML copy brings non-breaking and zero-width characters with it. They look like ordinary spaces, but they break searches, sorts and comparisons until they are normalised.

Two spaces after every full stop

Typewriter spacing survives in old documents and in anything typed by someone taught that way. Collapsing repeated spaces brings the whole file to one house style in a single pass.

A code or address that will not match

A single trailing space on a reference, SKU or email address is invisible and defeats an exact-match lookup. Trim spaces at the line ends and the comparison starts working.

Prose lifted from a PDF or a slide deck

Extracted text arrives padded with tabs and ragged leading spaces used for layout. Expanding or deleting the tabs and trimming the lines leaves plain, consistent paragraphs.

Questions

Does the text I paste in leave my browser?
No. Every rule runs in this browser tab using the page's own JavaScript, so nothing is transmitted or stored and the tool still works with the network disconnected.
Will it keep the indentation in my code?
Only if you switch off both Collapse repeated spaces and the line-end trimming, since either one flattens a leading run of spaces or tabs. Even then, a formatter built for the language is the better choice — this tool has no idea what a block is.
Why did my tab-separated columns turn into one?
Collapse repeated spaces treats spaces and tabs alike, so two or more tabs in a row become a single space even when Tabs is set to leave them as they are. Turn collapsing off to keep a tab-delimited table intact.
Why did a space appear inside one of my words?
That is the punctuation rule, which adds a space after a full stop followed by a capital letter. Filenames, initials in the form a.Bc and version strings are read as two sentences. Only URLs and email addresses are protected, so leave the setting off for text full of such tokens.
Which invisible characters does it actually remove?
Zero-width space, zero-width non-joiner, zero-width joiner, word joiner, byte-order mark and soft hyphen are deleted; no-break, narrow, medium, ideographic, Ogham and the en-quad to hair spaces become ordinary spaces. Nothing outside that list is touched by this rule. Use Whitespace Visualiser first when you want to see what is in the text before changing it.
Can it join wrapped lines back into paragraphs?
No. Line breaks are never merged here, only blank lines can be dropped. Remove Line Breaks is the tool that unwraps hard-wrapped text and rejoins words split across a line end.
Why does my output no longer end with a blank line?
Leading empty lines and every trailing whitespace character are stripped at the end of the run, regardless of the Blank lines setting. A leading line made of spaces only disappears if trimming is also on. If a trailing newline matters to whatever reads the file, add it back after copying.

Related tools