Skip to main content
Tools Star Hub

Text Tools

How to Remove Extra Spaces, Tabs and Blank Lines from Text

By Tools Star Hub Editorial Team · Published

Quick answer: paste your text into the Whitespace Remover, tick the cleanup you need, and copy the result. Trim each line removes spaces and tabs at both ends of every line. Collapse repeated spaces turns runs of spaces into one. Convert tabs to spaces swaps each tab for 2 or 4 spaces. Remove blank lines deletes empty rows, while Collapse multiple blank lines keeps one blank line between paragraphs. Trim entire document removes empty space at the very start and end.

Extra whitespace is invisible until it causes trouble. Double spaces look sloppy in published text, trailing spaces break exact-match comparisons and data imports, mixed tabs and spaces make code and tables misalign, and stacks of blank lines push content down a page. Cleaning it with fixed rules is faster and more consistent than hunting for it by hand.

What counts as whitespace?

Whitespace is any character that takes up space without printing a mark. The common ones are the ordinary space, the tab, and the line break that ends each line. Blank lines are lines that contain nothing, or only spaces and tabs.

Text copied from PDFs, web pages, email clients and word processors often carries extra whitespace: two spaces after a full stop, spaces at the ends of lines, tabs used for alignment, or several empty lines between paragraphs. Some sources also add non-breaking spaces, which look identical to normal spaces.

How to Remove Extra Spaces from Text: Trim, Tabs and Blank Lines — Tools Star Hub

What does each cleanup option do?

The options are separate switches, so you can combine them. Trim each line and Trim entire document are on by default. The rest are off until you tick them.

Whitespace options and what they change
OptionWhat it removes or changesSafe for code?
Trim each lineSpaces and tabs at the start and end of every lineNo, it removes indentation
Remove leading whitespaceSpaces and tabs at the start of lines onlyNo, it removes indentation
Remove trailing whitespaceSpaces and tabs at the end of lines onlyYes
Collapse repeated spacesTwo or more spaces in a row become oneNot for space-indented code
Convert tabs to spacesEach tab becomes 2 or 4 spacesYes, if the width matches
Remove blank linesEvery empty or space-only lineChanges layout
Collapse multiple blank linesRuns of blank lines become a single blank lineUsually yes
Trim entire documentBlank space before the first and after the last characterYes

When Trim each line is on, it already covers leading and trailing whitespace, so the two narrower options have no extra effect. Untick it if you only want one side trimmed. Remove blank lines takes priority over Collapse multiple blank lines if you tick both.

How do I clean code without breaking indentation?

Indentation is leading whitespace, so any option that removes it will flatten your code. That matters a great deal in Python and YAML, where indentation is part of the syntax, and it makes any language harder to read.

For code, untick Trim each line, then tick Remove trailing whitespace and, if your project uses spaces, Convert tabs to spaces with the width your project uses. Collapse multiple blank lines is usually safe. Leave Collapse repeated spaces off, because it would also shrink indentation made of spaces. That combination removes the invisible clutter that shows up in code review without changing structure.

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

Most current style guides for published writing use a single space after a full stop. Two spaces is a habit from typewriters and is still preferred by some writers and organizations, so check the guide you follow.

If you need single spacing, Collapse repeated spaces fixes it across a whole document in one pass. It also fixes double spaces that appear between words when text is joined from several sources.

Should I remove blank lines or collapse them?

Remove blank lines when every line is a separate record, such as a list of names, URLs or product codes, and an empty row would become an empty entry. Collapse multiple blank lines when the text has paragraphs, so the paragraphs stay separated by one empty line instead of three or four.

If what you actually want is one long paragraph with no line breaks at all, use the Remove Line Breaks tool. The Whitespace Remover keeps line breaks between non-empty lines.

Why do some spaces survive the cleanup?

Collapse repeated spaces matches the ordinary space character only. A non-breaking space, often pasted from web pages and word processors, is a different character, so a normal space next to a non-breaking one is not collapsed. Trim each line and Trim entire document remove non-breaking spaces at the ends as well, but the narrower Remove leading and Remove trailing options only look for ordinary spaces and tabs.

Tabs are converted before spaces are collapsed. If you tick both, a tab between two words first becomes several spaces and then a single space, which is usually what you want in prose but not in tab-aligned tables.

If two strings still refuse to match after cleaning, use Find and Replace to search for the odd character and replace it with a normal space, then run the Whitespace Remover again.

How to remove extra whitespace online

  1. Paste your text. Put the text in the Text box. It can be prose, a list, a CSV export or code, up to 400,000 characters.
  2. Pick the options. Keep the defaults for general text, or untick Trim each line and choose more specific options for code. If you convert tabs, choose 2 or 4 spaces.
  3. Clean the text. Run the tool. The result appears in its own box with line and character counts before and after, so you can see how much was removed.
  4. Copy or download. Copy the cleaned text or download it as cleaned.txt. The processing happens in your browser and nothing is uploaded.

Example

Tidying text pasted from a PDF

A paragraph copied from a PDF arrives with spaces at the end of each line and doubled spaces between some words. With Trim each line and Collapse repeated spaces ticked, each line is clean. Join the lines afterwards with Remove Line Breaks if you need one paragraph.

Cleaning a list before deduplicating it

A list of 300 product codes has stray spaces and blank rows. Trim each line plus Remove blank lines gives one clean code per line, ready for the Duplicate Line Remover.

Fixing a code snippet for review

A function has trailing spaces and tab indentation in a project that uses 4 spaces. Untick Trim each line, tick Remove trailing whitespace and Convert tabs to spaces with 4 spaces. Indentation is kept and only the invisible clutter goes.

Tips and limitations

Tabs are replaced literally

Each tab becomes a fixed number of spaces. Tabs used to line up columns at different positions may not line up afterwards, because a tab in an editor jumps to the next tab stop.

Keep a copy of the original

The input box is not changed, so you can adjust options and run again. Compare versions with the Text Diff tool if you need to confirm every change.

Spreadsheets and CSV

Trimming lines in a CSV only trims the ends of each row, not the spaces around each comma-separated value inside the row.

FAQ

How do I remove trailing spaces only?
Untick Trim each line and tick Remove trailing whitespace. Leading indentation stays as it is.
What is the difference between removing and collapsing blank lines?
Removing deletes every empty line. Collapsing keeps one empty line wherever there were two or more, so paragraphs stay separated.
Can I convert tabs to four spaces?
Yes. Tick Convert tabs to spaces and pick 4 spaces. The other choice is 2 spaces.
Will the tool join my lines into one paragraph?
No. It keeps line breaks between lines that have text. Use Remove Line Breaks to join lines.
Why are two spaces still between some words?
Make sure Collapse repeated spaces is ticked. If it is, one of the characters may be a non-breaking space, which the option does not match.
Is it safe to clean Python or YAML with this tool?
Yes, if you avoid options that remove leading whitespace. Use Remove trailing whitespace and Collapse multiple blank lines, and leave Trim each line and Collapse repeated spaces off.
What does Trim entire document do?
It removes blank lines and spaces before the first visible character and after the last one, leaving the inside of the text alone.
Does the tool show what changed?
It shows line and character counts before and after. Paste both versions into Text Diff to see each change.
Can I clean whitespace inside CSV fields?
Only partly. Collapse repeated spaces works anywhere in the line, but trimming only affects the start and end of each row.
Is there a size limit?
The tool accepts up to 400,000 characters at a time so the browser stays responsive. Split larger files into parts.
Will non-breaking spaces be cleaned?
Many cleaners treat regular spaces; paste into a plain field first if NBSP characters linger.
How do I preserve markdown code fences?
Skip minifying indented code blocks; clean prose separately from fenced samples.
Can I collapse spaces but keep paragraph breaks?
Choose a mode that trims within lines while leaving blank lines that mark paragraphs.
Why do double spaces appear after periods?
Old typing habits insert them; collapsing whitespace usually reduces them to one.
Is it safe for poetry with intentional gaps?
No—artistic spacing should be edited by hand so deliberate gaps survive.
How do leading spaces in lists behave?
Trimming lines can remove indentation that markdown or code relies on—preview first.
Can I strip spaces around commas in CSV?
Yes for simple files, but quoted fields with internal spaces need a CSV-aware editor.
Do zero-width characters count as spaces?
They are not normal spaces; use a dedicated Unicode cleaner if copy/paste inserts them.
Should I clean before or after spellcheck?
Clean first so spellcheck is not distracted by double spaces and stray tabs.
Will cleaning change my byte size much?
Prose often shrinks modestly; code with heavy indentation can shrink more.

Clean spaces, tabs and blank lines with the free Whitespace Remover.

To merge lines into one paragraph, use Remove Line Breaks.

To drop repeated rows after cleaning, try the Duplicate Line Remover.

Sources and further reading