Skip to content
ToolPlankDEV
Text Tools
100% In-Browser Execution

Updated:

Space Remover: Remove Extra Spaces from Text

Paste your text into this space remover to collapse double spaces, trim the start and end of each line and fix the odd spaces that come with text from PDFs and AI chats. Your line breaks stay where they are, and nothing is uploaded.

Options:

Your text

Input
0 chars · 0 lines

Text without extra spaces

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use Space Remover

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste the text you want to fix

    Paste into the Your text box, press Paste to read your clipboard, or drop a .txt file onto the box. Press Sample to load a short text with double spaces, tabs, odd spaces and blank lines.

  2. 02

    Choose what to remove

    Remove is set to Extra spaces, which turns every run of spaces into one. All spaces deletes every space but keeps your line breaks. All whitespace deletes spaces, tabs and line breaks.

  3. 03

    Adjust trim, tabs and odd spaces

    Trim each line clears spaces at the start, the end or both ends of every line. Treat tabs as spaces, Fix odd spaces and Squeeze blank lines handle tabs, non-breaking spaces and runs of empty lines. These four are greyed out in All whitespace mode.

  4. 04

    Copy or download the result

    The result updates as you type, and the line under it reads N removed, the number of characters that were taken out. Press Copy, or Download to save a .txt file.

What This Space Remover Does

This space remover cleans the gaps in your text without touching the words. By default it turns every run of two or more spaces into one, trims the spaces at both ends of each line, turns tabs into spaces and swaps odd Unicode spaces for normal ones. Line breaks stay where they are, so paragraphs and lists keep their shape.

A typical case is a sentence that picked up double spaces while being edited:

Text
Hello    world,   this  is   a  test.

With the default settings it comes out as:

Text
Hello world, this is a test.

The line under the result reads 9 removed. If you also want to join lines into one paragraph, run the result through Remove Line Breaks, which handles wrapped text from PDFs and emails.

A Worked Example with the Sample Text

Press Sample to load four lines of messy text. The first line has spaces at both ends and runs of three and four spaces. The second uses tabs between words and a non-breaking space before the word with. After three blank lines, the last line starts with spaces and contains a narrow non-breaking space and an em space.

With the default settings the output is:

Text
This sentence has too many spaces.
It was copied from a spreadsheet with tabs.



A PDF added odd spaces here.

The count reads 18 removed. The tabs and the three odd spaces are not part of that number, because each one is replaced by a normal space rather than deleted, so the length does not change. The three blank lines are still there. Turn on Squeeze blank lines and only one blank line is kept, which brings the count to 20 removed.

Remove All Spaces or Remove White Space Completely

Sometimes you want no spaces at all, for example in a phone number, a product code or a key that you need to paste into a form. Set Remove to All spaces and every space is deleted while each line stays on its own row. The line Call 0300 123 4567 or 0300 765 4321 becomes:

Text
Call03001234567or03007654321

All whitespace goes further and also deletes tabs and line breaks. That suits a long number that was split across lines. A card test number written as 4111 1111 on one line and 1111 1111 on the next becomes:

Text
4111111111111111

Because this mode deletes everything between the words, the trim, tabs, odd spaces and blank line options have nothing left to do, so they are greyed out while it is selected.

A ChatGPT and AI Space Remover for Odd Spaces

Text copied from an AI chat, a PDF or a web page often contains spaces that look normal but are different characters. The usual ones are the non-breaking space, the narrow non-breaking space, thin, en and em spaces, and the wide ideographic space used in Chinese and Japanese text. Find and replace for a double space misses them, and some forms and code editors treat them as letters rather than gaps.

With Fix odd spaces on, each of these becomes a normal space first and is then collapsed with its neighbours. A short list pasted from a chat, with a non-breaking space after the colon, a narrow one after 1. and a thin one inside Drink water, comes out as:

Text
Here are three tips:

1. Sleep early.
2. Drink water.

Options Explained

  • Trim each line: Both ends is the default. Start only clears leading spaces, End only clears trailing spaces, and Do not trim leaves the edges alone. Any run of spaces at an edge that is not trimmed is still collapsed to one space.
  • Treat tabs as spaces: on by default. Each tab is handled like a space, so tabs between words become a single space. Turn it off to keep tabs exactly as they are.
  • Fix odd spaces: on by default. Non-breaking, thin, en, em, ideographic and similar Unicode spaces become normal spaces. Turn it off if those characters are there on purpose, such as a non-breaking space that keeps 25 and kg together.
  • Squeeze blank lines: off by default. When on, it keeps at most one blank line in a row and drops blank lines at the very start and end.

When a White Space Remover Helps and When It Hurts

It helps with prose, lists, names and values copied between apps: a CV pasted from a PDF, a product description from a supplier's sheet, chat answers you are moving into a document, or a list you plan to clean further with Remove Duplicate Lines or prefix with Add Text to Each Line. Duplicates that differ only by a stray space become exact matches after this step.

Keep it away from text where spacing carries meaning:

  • Code and YAML. Leading indentation is trimmed by default and collapsed to one space even with Do not trim, so Python, YAML and nested lists lose their structure.
  • Tab-separated data. With Treat tabs as spaces on, the line name, tab, age becomes name age and the columns merge. Turn the option off first.
  • Markdown hard line breaks. Two spaces at the end of a line force a line break in Markdown. Trimming the end of the line removes them.
  • Aligned plain-text tables. Columns lined up with runs of spaces will shift once the runs are collapsed.

Remove Whitespace in JavaScript or Excel

If you need the same clean-up inside your own code, JavaScript can do it line by line. This keeps line breaks, collapses spaces, tabs and non-breaking spaces, and trims each line:

JavaScript
const clean = text
  .split("\n")
  .map((line) => line.replace(/[ \t\u00a0]+/g, " ").trim())
  .join("\n");

Watch out for the shorter text.replace(/\s+/g, " "). In JavaScript \s also matches line breaks, so that one-liner joins all your lines into one.

In Excel, TRIM trims a cell and collapses runs of normal spaces, but it ignores the non-breaking space, character 160, which is common in data copied from web pages. Wrap the cell in SUBSTITUTE(A1, CHAR(160), " ") before TRIM to catch it.

Limits, Line Endings and Privacy

  • The engine reads the text in one pass, so the time it takes grows in step with the length of the text. Up to 2,000,000 characters are accepted.
  • When you paste or upload text, the page turns Windows CRLF and old Mac CR line endings into LF, so the copied and downloaded result uses LF line endings.
  • It changes spaces only. Spelling, punctuation, capital letters and zero width characters are left as they are.
  • Your text is processed in your browser and is not uploaded. The Privacy Policy explains what the site does and does not collect.

Frequently Asked Questions

Technical Q&A for Space Remover

Common questions about edge cases, character encoding, and privacy guarantees.

Paste your text and leave Remove set to Extra spaces. Every run of two or more spaces becomes one space, and the spaces at both ends of each line are trimmed.

Set Remove to All spaces to delete every space and keep your line breaks. Choose All whitespace if tabs and line breaks should go too.

Such text can contain non-breaking, thin, em or other Unicode spaces that look like normal spaces but are different characters. Fix odd spaces turns them into normal spaces. Zero width characters are a separate problem, handled by the Invisible Character Remover.

Yes. Line breaks and blank lines are kept unless you choose All whitespace or turn on Squeeze blank lines.

Close, but not the same. Excel TRIM collapses runs of normal spaces in one cell and ignores non-breaking spaces, while this tool can also convert those and works on many lines at once.

Yes. The text is processed in your browser and is not sent to a server, and a .txt file you drop on the box is read the same way.

No. Zero width characters and the byte order mark are left in place. Use the Invisible Character Remover to find and remove them.

Yes. Turn off Treat tabs as spaces and tabs are kept as they are, while runs of normal spaces are still collapsed.

All whitespace is selected. That mode deletes every space, tab and line break, so trim, tabs, odd spaces and blank lines have nothing to act on.

It is the number of characters removed, shown as N removed. A tab or odd space that is replaced by a normal space is not counted, because the length stays the same.