Whitespace Remover
Remove extra spaces, tabs and line breaks from text instantly. Free whitespace cleanup tool.
Four Cleanup Options You Can Combine
Toggle any combination of four options: trim lines (removes leading and trailing spaces from each line), remove blank lines (deletes empty lines so the text closes up), collapse spaces (replaces runs of multiple spaces with a single space), and remove all whitespace (the nuclear option, strips every space, tab, and line break). Output updates live as you toggle. The first three are usually combined; the fourth is for special cases like generating a slug or a hash input.
Real example. Paste this in: ' Hello World \n\nThis has extra spaces' and turn on 'Trim lines' + 'Collapse spaces' + 'Remove blank lines'. Output: 'Hello World\nThis has extra spaces'. Two of the original 17 problem characters survive; the rest are gone. This is the single most common cleanup you will run on text copied out of PDFs, scraped websites, or messy email threads.
What Each Option Actually Does
Trim lines targets only line beginnings and ends, leaving spaces inside a line untouched - so 'word word' stays 'word word' but ' word word ' becomes 'word word'. Collapse spaces targets every run of two or more spaces inside a line, replacing them with one space - 'word word' becomes 'word word'. Run both together and 'word word' becomes 'word word' with no leading or trailing space. Remove blank lines acts on whole lines that contain nothing or only whitespace, dropping them entirely.
'Remove all whitespace' is exactly what it says: every space, tab, and newline disappears. 'Hello World' becomes 'HelloWorld'. Use it for generating clean strings to feed into hash functions, URL slugs (though the [slug generator](/slug-generator) is purpose-built for that), or compact concatenations. Most of the time you do not want this; you want trim + collapse + remove blanks instead.
Common Cleanup Scenarios
Pasting text out of a PDF: turn on all three of trim, collapse, and remove blanks. PDFs typically introduce trailing spaces, double-spaces between sentences, and blank lines between paragraphs that you do not want. Cleaning up text scraped from a website: same combination, plus consider running it through the [find and replace](/find-and-replace) tool afterwards to fix curly quotes or non-breaking spaces. Cleaning up code copied from Stack Overflow: just trim lines, since you want to keep blank lines and indentation intact.
One thing this tool does not handle: invisible Unicode characters like zero-width spaces (U+200B), zero-width joiners (U+200D), or non-breaking spaces (U+00A0). Those are not detected as 'whitespace' by JavaScript's regular whitespace pattern. If a line still looks misaligned after running the tool, copy it into a hex viewer or use the [find and replace](/find-and-replace) with regex mode to target those specific codepoints. The [text diff](/text-diff) tool will also reveal mystery whitespace differences when comparing two versions of the same paragraph.
Frequently Asked Questions
Does 'collapse spaces' affect tabs?
Yes. Tabs count as whitespace, so a sequence of tabs, mixed tabs and spaces, or runs of either gets collapsed to a single space when 'Collapse spaces' is on. If you need to preserve tab indentation in code, do not enable collapse spaces - use only 'Trim lines' instead.
Will it remove non-breaking spaces (U+00A0)?
Only with 'Remove all whitespace' enabled. The other three options use JavaScript's whitespace pattern which excludes some Unicode space characters. For non-breaking spaces and zero-width spaces specifically, use the [find and replace](/find-and-replace) tool with regex mode and the appropriate codepoint.
Is there a way to keep paragraph breaks but remove single line breaks?
Not directly in this tool. To do it, use [find and replace](/find-and-replace) with regex mode: replace single newlines (not double) with a space. Pattern: (?<!\n)\n(?!\n) replaced with a space. That is a more advanced operation than the four toggles here cover.
Can I undo a removal if I clean too aggressively?
Use Ctrl+Z or Cmd+Z in the input field to undo your paste, or paste again from your clipboard if the original is still there. The tool does not have an undo button because the cleanup runs live - just toggle the options off and the original text reappears in the output.
Related Tools
Text Reverser
Reverse text instantly. Free online text reverser for backwards text, palindromes, and more.
Text Sorter
Sort text lines alphabetically or reverse order. Free text sorting tool for lists and data.
Word Frequency Counter
Analyse word frequency in any text. See a sorted table and visual chart of the most common words with options to filter common words and set minimum length.