Whitespace Remover
Use the CaseSwitch Whitespace Remover to collapse extra spaces, trim edges, and tidy blank lines from Slack, HTML, or PDF pastes. Preserve line breaks stays on by default so lists keep their shape. Processing stays in this browser — nothing is uploaded.
Written by the CaseSwitch editorial team. We maintain these tools in the browser so drafts, keys, and images stay on your device.
Last reviewed: 23 July 2026
Processed locally in your browser. Nothing is sent to a server.
Paste or type text to convert. Output stays empty until there is input.
Character count: 0 · Word count: 0 · Line count: 0
Examples
Collapse internal spaces (preserveLines default)
Input
too many spaces
Output
too many spaces
Trim leading and trailing spaces
Input
leading and trailing
Output
leading and trailing
Collapse spaces per line; 3+ newlines → 2
Input
line one line two
Output
line one line two
Tabs collapse like spaces
Input
col1 col2 value
Output
col1 col2 value
Four blank-line gaps reduce to one blank line
Input
alpha beta gamma
Output
alpha beta gamma
Preserve line breaks off — flatten to one line
Input
keep me separate
Output
keep me separate
How to use
- Paste the messy text into the input panel.
- Leave Preserve line breaks on for lists and multi-line notes; turn it off only when you want one flattened line.
- Copy the cleaned result, or continue into another tool in this suite.
What this tool is for
Copied HTML, Slack, and PDFs leave runs of spaces that look fine on screen and fail in diffs. This tool collapses internal whitespace, trims each line, and (by default) keeps newlines while reducing three or more consecutive blank lines to a single blank line. Turn Preserve line breaks off when you want the whole paste flattened to one spaced line.
How it works
With Preserve line breaks on (the default), the text is split on newlines; each line has runs of whitespace (spaces and tabs) collapsed to a single space and is trimmed; lines are rejoined; runs of three or more newlines become two (one blank line); then the whole result is trimmed. With Preserve line breaks off, every whitespace run in the document — including newlines — collapses to a single space and the edges are trimmed, so the output is one line. There is no separate “trim only” switch: collapse and trim always run together.
When to use it
Cleaning CSV cells, tightening pasted UI copy, normalizing Slack or email spacing before a character count, and preparing text for a case converter or duplicate-line pass when padding would create false unique lines.
When not to use it
Do not collapse spaces in Python code, Makefile recipes, or `pre` formatted tables. Do not strip indentation you still need. Do not use this when your goal is to join wrapped prose into one paragraph — that is Remove Line Breaks.
How it compares to related tools
Remove Line Breaks joins wrapped prose into one flow. The Character Remover can delete all spaces if you put a space in the delete set — more aggressive than collapse. The Duplicate Line Remover is the usual next step after spacing is clean. Find and Replace is better for targeted phrase swaps.
Common mistakes
Collapsing spaces inside indented code or markdown nested lists. Expecting tabs to survive as tabs — they count as whitespace and collapse to spaces. Leaving Preserve line breaks on when you actually wanted a single line, or turning it off and losing a list structure you still needed.
Preserve line breaks on versus off
On (default) is the right mode for poetry drafts, bullet lists, and address blocks: each line is cleaned, and excessive blank lines shrink to a single gap. Off is the right mode when a CMS field must be one line or when newlines were accidental paste noise. Off is not the same as Remove Line Breaks with a custom replacement — it always uses a single space between former whitespace runs.
Tabs, blank lines, and empty input
Tabs are whitespace: they collapse to a normal space inside a line. Three or more consecutive newlines become exactly two, so you keep at most one blank line between blocks when preserve mode is on. The final trim removes a leading or trailing blank line on the whole result. Empty input produces empty output. The tool does not delete non-space characters or change letter case.
Frequently asked questions
What is the difference between trim and collapse?+
Trim removes spaces at the edges of each line (and of the whole result). Collapse turns two or more spaces or tabs in the middle into one. This tool always does both.
Are tabs whitespace?+
Yes. Tabs are treated as whitespace and collapse to a single space the same way repeated spaces do.
What does Preserve line breaks do?+
When on (default), newlines stay and only spaces within each line collapse; runs of three or more blank lines shrink to one blank line. When off, newlines are collapsed too and the output is a single line.
Will two blank lines in a row survive?+
With preserve mode on, three or more newlines become two (one blank line). A single blank line between paragraphs (two newlines) is kept.
Should I use this or Remove Line Breaks?+
Use Whitespace Remover to clean spaces while keeping a multi-line shape. Use Remove Line Breaks when wrapped PDF or email lines should become one continuous paragraph.
Is my text uploaded?+
No. Cleaning runs in this browser. Nothing is sent to a server.
Does CaseSwitch upload this text?+
No. Conversion, cleaning, and counting for this page run in your browser. Drafts are not sent to CaseSwitch for processing.
Related tools
Remove Line Breaks
PDF copy-paste, OCR output, old plain-text emails, chat logs wrapped at a fixed width, and comments that wrapped at column 80 when you wanted a single string for a CMS or spreadsheet cell.
Duplicate Line Remover
Deduping email lists, unique-ifying a keyword list, cleaning a changelog pasted twice, preparing a column for import, and removing repeated headers from a log extract. Use it when duplicates are exact line repeats and you want to keep original order. Pair with the Whitespace Remover first if trailing spaces or mixed tabs make visually identical lines look different to you but not to the tool.
Plain Text Converter
Pasting a README snippet into Slack as plain text, cleaning a CMS export, preparing copy for a system that escapes HTML badly, and getting unstyled words ready for a case converter.
Find and Replace Text
Renaming a term across a draft, normalizing spelling variants, stripping a repeated prefix, fixing a typo that appears dozens of times, and small regex cleanups (optional digits, `colou?r`-style variants, capture-friendly patterns). Test on a short sample before pasting a long document.
Character Remover
Cleaning invoice numbers out of a description, removing emoji from a slug candidate, stripping punctuation before a frequency count, deleting a separator from a pasted column, and preparing a string for a case converter when leftover marks would become part of a token.
Remove Text Formatting
Cleaning chat messages that used *bold*, turning a Markdown outline into a meeting agenda, preparing text for a case converter, and peeling markers from a CMS paste.