Skip to content
TextBench Lab

Remove Extra Spaces

Clean up messy whitespace: trim every line, collapse double spaces, turn tabs into spaces, and strip non-breaking and zero-width characters. You see exactly what was fixed. It runs in your browser, so nothing is uploaded.

Fixes

Line breaks are always kept. The zero-width joiner and non-joiner stay, so emoji and scripts like Urdu or Hindi are never broken.

Fixes
0
Before
0
After
0

How to remove extra spaces

  1. Paste your text

    Paste text from a PDF, a web page, an email or a spreadsheet, up to 1,000,000 characters.

  2. Pick the fixes

    Trimming, collapsing spaces, tabs and invisible characters are on by default. Turn off what you want to keep.

  3. Check what changed

    The report counts each kind of fix. Show invisible characters to see spaces, tabs and hidden characters as symbols.

  4. Copy the clean text

    Copy the result or download it as a .txt file, with LF or CRLF line endings.

Features

  • Every kind of space

    Double spaces, tabs, non-breaking spaces, thin spaces and zero-width spaces are all handled.

  • Lines stay lines

    Line breaks are kept, so lists, code and paragraphs keep their shape. Only blank lines are optional.

  • A clear report

    See how many spaces were trimmed or collapsed and how many hidden characters were removed.

  • Private

    Everything happens in your browser. Your text is never uploaded or stored.

What this tool does

Text copied from a PDF, a web page, an email or a spreadsheet often looks fine but is full of messy whitespace: two spaces after a full stop, spaces at the end of every line, tabs in the middle of a sentence, and characters you cannot see at all. This tool removes extra spaces and fixes all of these in one pass, while every line stays where it was. It then tells you exactly what it fixed, so you can trust the result.

What gets fixed

Every fix can be turned off, so you only change what you want to change:

  • Trim the start and the end of each line. Spaces and tabs before the first word and after the last word of a line are removed. Trailing spaces are invisible, but they break exact matches in spreadsheets and show up as noise in code reviews.
  • Collapse multiple spaces. A run of two or more spaces between words becomes one space. When the start of the line is not trimmed, its indentation is left alone, so code and nested lists keep their shape.
  • Turn tabs into spaces. Each tab becomes 1, 2, 4 or 8 spaces. With collapsing on, a tab between two words simply becomes one space.
  • Replace non-breaking and special spaces. The non-breaking space, the narrow and thin spaces used in typography, the figure space and the wide ideographic space all become an ordinary space.
  • Remove zero-width characters. The zero-width space, the word joiner, the byte order mark and the soft hyphen are deleted.

Line breaks and blank lines

Line breaks are never removed, which is what makes this tool different from the others on this site. Every line of your text stays a line. You choose what happens to blank lines: keep them, collapse each group into a single blank line (with none at the start or the end), or remove them all. A line that holds only spaces or tabs counts as blank.

All line breaks are written in one style. Choose LF for the web, Mac and Linux, or CRLF for Windows tools that expect it. Line separator characters (U+2028 and U+2029) that some apps paste become normal line breaks too.

The report: see what was fixed

Under the result, the tool counts every kind of fix: spaces trimmed at line starts and ends, extra spaces collapsed, tabs converted, special spaces replaced, zero-width characters removed, blank lines removed and line endings changed. Each character is counted once, under the first fix that changed it: a tab at the start of a line counts as trimmed, not also as converted, so the total is never more than the characters in your text. If everything shows zero, your text was already clean with these settings.

Tick Show invisible characters to see your original text or the clean result with symbols: a middle dot for each space, an arrow for a tab, ↵ at each line break, and a short name in brackets for special characters, such as [NBSP] for a non-breaking space or [ZWSP] for a zero-width space. This is the quickest way to find out why two words that look the same do not match.

Why invisible characters cause trouble

A non-breaking space looks exactly like a normal space, but computers treat it as a different character. A search for two words with a normal space between them will not find the same words joined by a non-breaking space. Spreadsheet lookups fail, a username will not log in, and a sort puts items in a strange order. Zero-width spaces are worse, because they take up no room at all: a word can contain one and still look perfect.

These characters arrive with copied text. Web pages use non-breaking spaces to keep numbers and units together, word processors insert them after short words in some languages, and PDFs often add them when text is extracted.

What is never removed

Some invisible characters are needed. The zero-width joiner builds emoji such as family and profession emoji and flags with extra parts, and both the joiner and the non-joiner shape letters correctly in Urdu, Persian, Arabic, Hindi and other scripts. Removing them would break the text, so this tool always keeps them. Bidirectional marks, which keep right-to-left and left-to-right text in the right order, are kept as well.

Which tool to use

Use this one when the words and lines are right and only the spacing is wrong. To join lines into one paragraph, use Remove Line Breaks instead. To delete repeated lines in a list, use Remove Duplicate Lines. Cleaning spaces first often helps those tools, because two lines that differ only by a trailing space are then seen as equal. The guide to cleaning a keyword list shows the full routine.

Spaces count as characters, so cleaning changes a character count. Check the result with the character counter, and read when word count or character count matters or how to shorten text to a character limit.

Privacy

Your text is cleaned in your browser. It is not uploaded, saved or tracked, and there is no sign-up. Text is limited to 1,000,000 characters so the page stays fast. Like every page on this site, this one may show ads from third-party vendors once ads are switched on, and those vendors can use cookies. Read the privacy policy for details.

Frequently asked questions

How do I remove double spaces from text?

Paste your text and keep Collapse multiple spaces ticked. Every run of two or more spaces inside a line becomes one space, and the report shows how many extra spaces went.

What is a non-breaking space?

A space character (U+00A0) that stops a line from wrapping between two words. It looks like a normal space, but search, sorting and spreadsheet formulas treat it as a different character. This tool turns it into a normal space.

What are zero-width characters?

Characters with no width at all, such as the zero-width space and the byte order mark. They come along when you copy from web pages or PDFs and can break search, passwords and code. They are removed here.

Will it break emoji or text in Urdu, Arabic or Hindi?

No. The zero-width joiner and non-joiner are never removed, because emoji sequences and many scripts need them. Bidirectional marks stay too.

Does it remove line breaks?

No, every line stays on its own line. You can only remove blank lines or collapse them to one. To join lines into one paragraph, use the Remove Line Breaks tool.

Is my text uploaded?

No. Everything happens in your browser and nothing is sent or saved. Text is limited to 1,000,000 characters so the page stays fast.

Topics