Whitespace Cleaner

Remove extra spaces, trim lines, delete blank lines, flatten paragraphs, and replace tabs, all with live preview.

runs locally on your browser. Your data never leaves your device.

Common Use Cases

Clean up text pasted from a PDF that has extra line breaks at every column wrap
Remove trailing spaces from every line in a data file before importing it into a database
Convert tab-indented content to space-indented for systems that don't handle tabs correctly
Strip non-breaking spaces from content copied from a web page before pasting into a form

About Whitespace Cleaner

Unwanted whitespace is one of the most persistent annoyances in text processing. It appears when copying text from PDFs (which often introduce extra spaces and line breaks at PDF rendering boundaries), from Word documents (where non-breaking spaces ` ` are common), from web pages (where HTML rendering collapses whitespace visually but the raw copy retains it), from spreadsheet cells, and from code editors where trailing spaces are left by developers.

The consequences range from cosmetic (text looking oddly spaced) to functional (string comparisons failing because "hello " ≠ "hello", CSV parsing breaking on cells with leading spaces, database queries missing matches due to stored whitespace). Some systems, like some mail servers, older APIs, and certain XML parsers, are particularly sensitive to unexpected whitespace characters.

This tool offers several targeted cleaning operations: trim leading and trailing whitespace from every line; collapse multiple consecutive spaces into one; remove all blank lines; remove lines that contain only whitespace (whitespace-only lines look blank but contain spaces or tabs); convert all tab characters to spaces (with a configurable tab width); and strip non-breaking spaces (` `, Unicode U+00A0) which look identical to regular spaces but behave differently in string comparisons and some parsers.

You can apply any combination of these operations independently, and the live preview updates as you toggle each option so you can see exactly what will change before copying the result.

Frequently Asked Questions

What is a non-breaking space and why does it cause problems?
A non-breaking space (Unicode U+00A0, HTML  ) looks identical to a regular space but behaves differently: it prevents a line break from occurring at that position, and most programming languages' string comparison and trimming functions do not treat it as whitespace. Text copied from web pages and Word documents often contains non-breaking spaces, which can break string comparisons, database matches, and CSV parsing.
What is the difference between 'trim lines' and 'remove blank lines'?
'Trim lines' removes leading and trailing whitespace from every line (so ' hello ' becomes 'hello') but keeps all lines including empty ones. 'Remove blank lines' deletes lines that contain zero characters. A line with only spaces is not blank unless you also enable 'trim lines' first (or use the 'remove whitespace-only lines' option).
Why does my text from a PDF have weird spacing?
PDF rendering engines don't store text as simple character strings; they store character positions on a page. When you copy text from a PDF, the copy-paste mechanism often inserts extra spaces or line breaks to approximate the visual layout. Extra spaces appear where large visual gaps existed (like between columns), and hard line breaks appear at every PDF text line boundary.
What does 'flatten paragraphs' do?
'Flatten paragraphs' joins lines within each paragraph into a single line, while preserving the blank-line separation between paragraphs. It's useful when text copied from a PDF or Word document has been word-wrapped with hard line breaks at narrow column widths, and you want to restore it to normal flowing prose.