Skip to content

Whitespace Remover

Trim lines, collapse repeated spaces and remove empty lines, tabs or line breaks. Non-breaking and full-width spaces in copied text become ordinary spaces.

0 characters · 0 lines

Lines

Spaces

0 characters · 0 lines

What you enter is processed only in this browser and is never sent to a server. How it works

Multiple spaces between Hello and world reduced to a single space

How to use

The options are split into two groups, “Lines” and “Spaces”, and you can turn on as many as you need. Three common ones are already on when you open the page.

  • Trim each line
  • Collapse multiple spaces into one
  • Convert non-breaking and full-width spaces to ordinary spaces

So pasting text into “Input” is enough to get a tidier copy in “Output”, with the whitespace at the edges of each line gone and doubled spaces between words reduced to one. Line breaks, empty lines and tabs are left alone in this starting state.

The options by example

Take these three lines. Invisible characters are written as · (space) and → (tab). The second line is empty.

··aa···bb··

→cc·dd→
Options on Result
Starting state (three options) Three lines: aa·bb, an empty line, cc·dd
Starting state + Remove empty lines Two lines: aa·bb, cc·dd
Starting state + Remove empty lines + Remove line breaks (Join with a space) One line: aa·bb·cc·dd
Starting state + Remove empty lines + Remove line breaks (Join with nothing) One line: aa·bbcc·dd
Starting state + Remove all spaces and tabs Three lines: aabb, an empty line, ccdd

Cleanup options

The options in the “Lines” group:

  • Trim each line: removes spaces and tabs at the start and end of every line. Whitespace in the middle of a line is kept.
  • Remove empty lines: removes lines with no characters and lines that hold only whitespace.
  • Remove line breaks: merges all lines into one. Turning it on reveals “Join with”, where you choose between “Join with a space” and “Join with nothing”.

The options in the “Spaces” group:

  • Collapse multiple spaces into one: reduces two or more spaces in a row to one. It counts spaces only, so a run with a tab in the middle is not reduced. For that, turn on “Convert tabs to spaces” too.
  • Remove all spaces and tabs: deletes every space and tab. Line breaks stay. With this on, “Collapse multiple spaces into one” has nothing left to do, so it is locked.
  • Convert tabs to spaces: replaces each tab with a single space. It does not pad with as many spaces as the tab was wide.
  • Convert non-breaking and full-width spaces to ordinary spaces: turns non-breaking spaces (U+00A0) and full-width spaces (U+3000) into ordinary spaces (U+0020). A line indented with full-width spaces loses that indent to “Trim each line” only when this option is on.

Order of operations

Whatever order you switch them on in, the options are always applied in this sequence.

  1. Convert non-breaking and full-width spaces to ordinary spaces
  2. Convert tabs to spaces
  3. Trim each line
  4. Remove empty lines
  5. Remove line breaks
  6. Collapse multiple spaces into one
  7. Remove all spaces and tabs

Each step works on the output of the one before. Tabs become spaces early, so aa→→bb, separated by two tabs, is reduced to aa·bb at step 6. Line breaks are also removed before spaces are tidied, so any doubled spaces created by joining lines are cleaned up at step 6 as well.

Whitespace you shouldn’t clean up

Where whitespace carries meaning, choose your options with care.

  • Code and config files where indentation is syntax: “Trim each line”, on from the start, strips all indentation. Python code and YAML files mean something different without it, so turn this option off for them.
  • Tables with tab-separated columns: a table copied from a spreadsheet has tabs between its columns. “Convert tabs to spaces” or “Remove all spaces and tabs” erases the column boundaries, and the text can no longer be pasted back as a table.
  • English words hyphenated across a line break: text that ends one line with inter- and starts the next with national comes out of “Remove line breaks” as inter- national. The hyphen is not removed for you, so fix it by hand.

Frequently asked questions

I turned on "Remove all spaces and tabs", but there are still gaps. Why?

They look like ordinary spaces but are different characters. Text copied from a web page often contains non-breaking spaces (U+00A0), and text typed with a Japanese or Chinese keyboard often contains full-width spaces (U+3000). "Convert non-breaking and full-width spaces to ordinary spaces" has to be on for these two to be turned into ordinary spaces first and then removed with the rest. Other whitespace characters, such as the zero-width space (U+200B) and the thin space (U+2009), aren't handled by this tool and stay where they are.

When removing line breaks, should I pick "Join with a space" or "Join with nothing"?

Pick "Join with a space" when the lines break between words. That covers sentences that were wrapped where a space would go. Without it, the last word of one line fuses with the first word of the next. Pick "Join with nothing" when the lines were cut in the middle of a word. That covers sentences copied from a PDF and cut at a fixed number of characters, as well as long numbers and code fragments split over several lines.

After removing line breaks, the result ends with an extra space. How do I avoid it?

When the input ends with a line break, whatever follows it counts as one empty line, and that empty line is joined to the line before it with a space. The two lines a, b with one more line break after them give 'a b' plus a trailing space, 4 characters in all. Turn on "Remove empty lines" as well and the empty line is dropped first, so no trailing space appears.

Last updated: