Remove Whitespace

Remove extra spaces and blank lines, or join lines into one

About Remove Whitespace

Remove Whitespace cleans spacing in five ways. Remove all extra collapses repeated spaces and tabs, trims every line, and turns each run of blank lines into one, dropping those at the very start and end. Remove extra spaces does the same inside lines but keeps every blank line. Remove leading and Remove trailing trim one side of each line only. Join into one line replaces every run of whitespace, line breaks included, with a single space; it is the only button that merges lines. All five run on your device, inside this page.

Example

Remove all extra: spaces and the tab are collapsed, each line is trimmed, and three blank lines become one.

Text

  Dear   team,	



The  report is   ready.  
Thanks,

After "Remove all extra"

Dear team,

The report is ready.
Thanks,

How to remove extra spaces from text

  1. 1Paste your text.
  2. 2Click "Remove all extra", "Remove extra spaces", "Remove leading", or "Remove trailing" to clean spacing while keeping every line of text.
  3. 3Click "Join into one line" only to turn the whole text into a single line.
  4. 4Click "Copy", or save the cleaned text with "Download" (cleaned.txt).

Formats and limits

Spaces handled
Spaces, tabs, non-breaking spaces, and the other Unicode spaces JavaScript treats as whitespace
Not removed
Zero-width spaces (U+200B), which JavaScript does not treat as whitespace
Line breaks
Windows, Mac, and Unix read; the result uses Unix line breaks
Output
Cleaned text shown under the buttons, which Download saves as cleaned.txt

Common uses

Text copied from a PDF or a web page
A paragraph pasted from a PDF arrives with double spaces and non-breaking spaces between words; "Remove all extra" leaves single spaces and keeps the lines in place for you to review.
A list to deduplicate or import
Email addresses pasted from a spreadsheet carry trailing spaces that make two copies of one address look different; "Remove extra spaces" trims every line first, and Remove Duplicate Lines then finds the real repeats.
An address for a one-line form field
A postal address copied on three lines from an email goes into a single-line field after "Join into one line", which puts one space where each line break was.

Which tool to use

  • Find and Replace: to delete every space, including those between words, or to target one character such as a zero-width space, which this page leaves in place.
  • Remove Duplicate Lines: to drop repeated lines; its option to ignore surrounding spaces only affects the comparison, and the lines it keeps are not trimmed.
  • Text to List: to turn cleaned lines into a bulleted, numbered, or comma-separated list; it skips blank lines by itself.

Where your text is processed

The five clean-ups are regular-expression replacements run by your browser on this page, so the text is not uploaded or stored anywhere. If the clipboard refuses a copy, the page shows "Copy failed" and sends the message "Copy to the clipboard failed." with the tool name and browser version, without any of your text, to our error log.

Frequently asked questions

Will it merge my lines?

No, unless you click "Join into one line". The four other buttons keep every line of text where it is; "Remove all extra" only shortens runs of blank lines to one and drops blank lines at the start and end.

Does it clean non-breaking spaces from web or PDF text?

Yes. Non-breaking spaces and the other Unicode spaces that JavaScript treats as whitespace are collapsed like ordinary spaces. Zero-width spaces are not whitespace for JavaScript, so they stay in the text.

Can I remove every space, even between words?

No. Every button keeps at least one space between words, and "Remove leading" and "Remove trailing" leave the spacing inside lines untouched. To delete all spaces, use Find and Replace with a single space in Find and nothing in Replace with.

Can it fix a PDF paragraph broken into short lines?

Yes. "Join into one line" puts it back on one line with single spaces. A word split by a hyphen at the end of a line keeps the hyphen and gains a space, as in hyph- enated, so check those afterward.

Will it break the indentation of code or nested lists?

"Remove all extra" and "Remove extra spaces" trim the start of every line, so the indentation goes and Python code stops working. "Remove trailing" cleans only the ends of lines and keeps the indentation as it is.

Does it remove tabs?

Yes. Inside a line a tab counts as a space, so "Remove all extra" and "Remove extra spaces" turn a run of tabs and spaces into one space, and "Remove leading" deletes tabs at the start of each line. Tab-separated columns pasted from a spreadsheet therefore come out separated by single spaces.

Can I join broken lines but keep the paragraph breaks?

Not in one step, because "Join into one line" merges the paragraphs too. Paste and join one paragraph at a time, or use "Remove all extra" if the short lines can stay.

Why does it say "Result is empty"?

The text held nothing but spaces, tabs, and line breaks, so the clean-up left no characters. "Remove all extra" and "Join into one line" give that message for such text.

Tips and tricks

  • ✓Run "Remove trailing" on code before sharing it: it strips spaces at line ends and touches nothing inside the lines.