␣ Whitespace Remover

Remove or clean up extra whitespace and line breaks in a block of text, all at once. Combine options as needed: trim leading/trailing whitespace per line, collapse repeated spaces into one, remove blank lines, or strip all whitespace entirely.

How to use

  1. Enter the text you want to clean up.
  2. Choose the options to apply — trim per line, collapse repeated spaces, remove blank lines, or remove all whitespace.
  3. The cleaned-up result appears automatically. Use the "Copy" button to copy it.

How the calculation works

This tool applies the options you select in the following order. 1. Trim leading/trailing whitespace per line: removes whitespace (spaces, tabs, full-width spaces) at the start and end of each line. 2. Collapse repeated spaces into one: replaces runs of two or more spaces or tabs inside a line with a single space. 3. Remove blank lines: removes lines with no content, including lines that contain only whitespace. "Remove all whitespace" overrides the other options and removes every whitespace character, including line breaks and full-width spaces, leaving a single string. Because the tool uses the regular expression \s, full-width spaces (U+3000) and non-breaking spaces also count as whitespace. However, "Collapse repeated spaces into one" only targets regular spaces and tabs, so full-width spaces inside a line are left as they are.

Worked example

Input (extra spaces at the start and end of lines and between words) ␣␣Hello␣␣␣World␣␣ ␣␣This␣␣has␣␣␣extra␣␣␣spaces.␣␣ Default (trim + collapse repeated spaces) Hello World This has extra spaces. With "Remove blank lines" also on Hello World This has extra spaces. (␣ stands for a space)

Things to be aware of

  • Full-width spaces inside a line are not affected by "Collapse repeated spaces into one". Use the full-width/half-width converter to turn them into regular spaces.
  • "Remove all whitespace" also removes the spaces between English words, joining them together.
  • Removing leading whitespace can break text where indentation matters, such as program code or YAML.
  • Your text is processed in the browser and is never sent anywhere.

FAQ

Are tab characters treated as whitespace too?

Yes — "Collapse repeated spaces" collapses runs of spaces and tabs into a single space.

What does "Remove all whitespace" do?

It strips every whitespace character, including line breaks, joining the text into one continuous string. The other options are disabled while this is on.

How do I clean up extra blank lines from pasted text?

Turn on "Remove blank lines" to strip out every line with no content (including lines that only contain whitespace).