Remove Extra Spaces

A tool to remove extra spaces cleans text by turning every run of spaces into a single space and deleting spaces at the start and end of each line. Paste your text, choose the options you need, and copy the result. It also converts tabs and no-break spaces, and can tidy spaces around punctuation.

Runs in your browser. Your text is never uploaded.

How to use the remove extra spaces

  1. Paste your text into the top box. The cleaned text appears underneath as you type or paste.
  2. Leave the first four options ticked for ordinary text. They collapse repeated spaces, trim each line, and treat tabs and no-break spaces as normal spaces.
  3. Tick Keep indentation if the text is code or an outline whose leading spaces matter. Tick Remove spaces before punctuation to fix gaps such as “word ,”, and Reduce blank lines to one to close large gaps between paragraphs.
  4. Check the note under the result, which says how many spaces were removed, then press Copy result or Download .txt.

How extra spaces are removed

The tool works one line at a time, so your line breaks stay where they are. For each line it applies the steps below in order, skipping any option you have switched off.

  1. Standardize the spaces. Tabs and the special spaces that look like a space but are different characters (the no-break space, the en and em spaces, the thin and hair spaces, the narrow no-break space and the ideographic space) are changed into an ordinary space. A search for a normal space will not find a no-break space, which is why text copied from web pages and word processors often keeps its gaps after a find and replace.
  2. Collapse repeated spaces. Every run of two or more spaces becomes one space.
  3. Trim the line. Spaces at the start and end of the line are deleted. With Keep indentation on, only the end of the line is trimmed and the start is left as it was.
  4. Tidy punctuation (optional). A space before a comma, full stop, semicolon, colon, exclamation mark, question mark or closing bracket is removed, and so is a space after an opening bracket.
  5. Reduce blank lines (optional). A run of empty lines is cut down to a single empty line.

The punctuation option is off by default because some languages and styles put a space there on purpose. French typography, for example, places a space before a colon, a question mark and an exclamation mark. Zero-width characters are invisible but are not spaces, so this tool leaves them alone. Line endings are saved as plain line feeds, so text from Windows (carriage return plus line feed) comes out with single line feeds.

Worked example

Below, a middle dot (·) marks an ordinary space, an arrow (→) marks a tab and a degree sign (°) marks a no-break space, so you can see what the tool sees:

··Dear···customer·,°°thank·you·for·your···order.··



····Items:→→one·,··two··and···three··

With the default options, 20 space characters are removed or converted. The two no-break spaces and the tabs become ordinary spaces, runs collapse to one, the lines are trimmed and the indentation goes:

Dear·customer·,·thank·you·for·your·order.



Items:·one·,·two·and·three

With Keep indentation, Remove spaces before punctuation and Reduce blank lines to one switched on, 16 space characters go. The indented line keeps its four spaces, the gaps before the commas close and the three empty lines shrink to one:

··Dear·customer,·thank·you·for·your·order.

····Items:·one,·two·and·three

What counts as a space

CharacterCodeHandled as
SpaceU+0020An ordinary space
TabU+0009A space, unless you untick Treat tabs as spaces
No-break spaceU+00A0A space, with the special spaces option on
En space, em space, thin space, hair spaceU+2000 to U+200AA space, with the special spaces option on
Narrow no-break spaceU+202FA space, with the special spaces option on
Ideographic spaceU+3000A space, with the special spaces option on
Zero-width spaceU+200BNot changed. It is invisible but is not classed as white space

Frequently asked questions

Why does my text have double spaces?

The usual causes are a habit of typing two spaces after a full stop, text copied from a justified PDF or an email, and find-and-replace edits that delete a word but leave both spaces around it. The tool collapses all of these to one space.

Should there be one space or two after a full stop?

Modern typesetting uses one space, and the two-space habit comes from the typewriter. Web browsers also collapse repeated spaces when they show a page. If you are writing for a publisher, school or journal, follow its style guide.

Why do some gaps survive when I search for a space and replace it?

They are probably no-break spaces or another special space, which are different characters from the ordinary space. Keep “Treat no-break and other special spaces as spaces” ticked and this tool converts them for you.

Will it damage code or tab-separated data?

It can, if you leave every option on. For code, tick Keep indentation. For tab-separated data, untick Treat tabs as spaces so the tabs between columns stay. Your original text is never changed, so you can try the options safely.

Does it remove line breaks?

No. Every line stays on its own line. To join lines into one paragraph, use the remove line breaks tool.

Is my text uploaded or stored?

No. The spaces are removed in your browser and your text never leaves your device.

Sources and references