Whitespace Cleaner

Clean up messy whitespace: trim lines, collapse multiple spaces, remove blank lines, and normalize line endings. Configurable options.

Your data never leaves your browser

How to Use

  1. 1

    Paste your text

    Enter text with messy whitespace in the input area.

  2. 2

    Select cleaning options

    Check the options you want: trim lines, collapse spaces, remove empty lines, normalize line endings.

  3. 3

    Click Clean

    The cleaned output appears with your selected whitespace rules applied.

What is Whitespace Cleaner?

A whitespace cleaner normalizes and removes unwanted whitespace from text. Unlike a simple trim, this tool offers granular control: trim each line, collapse consecutive spaces into one, remove blank lines, strip trailing whitespace, and normalize line endings from CRLF (Windows) to LF (Unix). Each option is independent, so you can mix and match exactly the cleaning you need.

This is especially useful for cleaning up code, configuration files, CSV data, or text copy-pasted from web pages or PDFs that often contain invisible whitespace artifacts (non-breaking spaces, tabs disguised as spaces, mixed line endings). It is also the right tool for fixing text that looks fine but causes weird `diff` results or git noise.

For removing only blank lines, use the [Empty Line Remover](/tools/empty-line-remover/). To clean text and then count it, follow up with [Character Counter](/tools/character-counter/) or [Word Counter](/tools/word-counter/). For sorting cleaned lines, see [Line Sorter](/tools/line-sorter/).

FAQ

What does 'Collapse multiple spaces' do?
It replaces sequences of two or more consecutive space characters with a single space. Tabs and other whitespace are not affected by this option.
What is the difference between 'Trim lines' and 'Trim trailing only'?
'Trim lines' removes whitespace from both the beginning and end of each line. 'Trim trailing only' removes whitespace from the end but preserves leading indentation — useful for code where indentation matters.
What does 'Normalize line endings' mean?
It converts Windows-style line endings (CRLF, \r\n) to Unix-style (LF, \n). This prevents issues when moving files between operating systems or committing to Git.
What is the difference between CRLF and LF line endings?
CRLF (`\r\n`, two characters) is the Windows line ending. LF (`\n`, one character) is the Unix/Linux/macOS line ending. Mixing them in the same file causes problems: Git produces noisy diffs, code editors show weird whitespace, and some scripts fail to parse correctly. Most modern projects use LF everywhere (configured via `.gitattributes`). The 'Normalize line endings' option converts CRLF to LF.

Related Articles

Related Tools