ToolBook
Support us on Ko-fi
Help us keep this free, forever

Whitespace & Newline Remover

How to remove whitespace from text

Paste text, pick the cleanup rules, copy the cleaned output.

  1. Paste your text

    Drop the source text into the input panel: code, prose, CSV, config file, or anything else with messy spacing. The whole document stays in your browser.

  2. Pick the cleanup rules

    Toggle trim per-line, collapse multi-space, collapse or remove blank lines, strip tabs, or join lines. Each toggle applies independently, so combine the ones you need or hit "Compact" for a sensible default.

  3. Tune the line endings and tabs

    Set tabs-to-spaces (0 keeps tabs as-is), and pick LF, CRLF, or preserve for the line ending style. This is how you normalize a file going from Windows to Unix or vice versa.

  4. Watch the live before/after counts

    Character count, line count, and whitespace removed update instantly so you can see exactly how much got stripped. Big delta means messy input; small delta means it was already clean.

  5. Copy the cleaned text

    The output panel shows the cleaned version. One click puts it on your clipboard, ready to paste back into your editor, email, or wherever you grabbed it from.

Frequently asked questions

How do I remove whitespace from text online?

Paste your text into the input panel, toggle the cleanup rules you want (trim lines, collapse spaces, remove blank lines, strip tabs), and the cleaned text appears live in the output panel. Hit Copy to put it on your clipboard. Everything runs in your browser, so the text is never uploaded.

How do I remove blank lines from text?

Toggle "Remove blank lines" to delete every empty line, or toggle "Collapse blank lines" to keep one blank line wherever there were several in a row. Collapse is the safer default for prose; Remove is right when you want a tightly packed list with no gaps between items.

How do I remove all line breaks or join lines into one?

Toggle "Join into one line" to remove every newline and join the lines back together with a single space. Useful when you have text that was wrapped at 80 columns and you want it as one continuous paragraph, or when pasting bullet points back as a flowing sentence.

What's the difference between "Trim lines" and "Collapse multi-space"?

Trim lines removes leading and trailing whitespace from each line. Collapse multi-space replaces runs of two-or-more spaces inside a line with a single space. Both are independent, so use one, the other, or both. Trim is on by default because trailing whitespace breaks markdown, YAML, and many config formats.

When should I use "Remove all spaces" vs "Collapse multi-space"?

Remove all spaces is rare. It is only useful when concatenating identifiers or stripping spaces from numeric strings ("1 234 567" becomes "1234567"). For prose cleanup, you almost always want Collapse, not Remove. Once you remove every space, the text becomes one giant token.

What does "Normalize line endings" do?

Different operating systems use different newline characters: Unix and modern Macs use LF (\n), Windows uses CRLF (\r\n), classic Macs used CR (\r). Mixed line endings in the same file cause Git to flag "false changes" and can break shell scripts. Normalize forces one style across the whole document.

Does this strip Unicode whitespace too?

The "Trim lines" toggle uses JavaScript's \s class, which catches non-breaking spaces (U+00A0), zero-width spaces (U+200B), and most Unicode whitespace. So invisible unicode characters get cleaned along with normal spaces when you paste from word processors, PDFs, or web pages.

Can I convert tabs to spaces or strip tabs entirely?

Yes. Set the "Tabs to spaces" field to 2, 4, or whatever your style guide uses. Set it to 0 (or toggle "Strip tabs") to remove tabs entirely. Useful when pasting code from one editor into another with different tab width settings, or when prepping text for a system that disallows tab characters.

Is my text uploaded to a server?

No. The whitespace remover runs entirely in your browser. The text you paste never leaves your machine, so you can clean confidential or large documents without worrying about logs or third-party storage.

The whitespace cleanup field guide

The four common whitespace problems, the right verb to fix each, and when to leave it alone.

Why text shows up dirty more often than you'd think

Copy-paste is leaky. The simple act of moving text from one place to another picks up trailing spaces, double spaces, mismatched tabs, blank lines that shouldn't exist, and Windows line endings sneaking into Unix files. Most of the time you don't notice, until a YAML parser breaks, a markdown table fails to render, a CSV row doesn't match, or Git keeps flagging "changes" that look like nothing changed.

This tool is the opposite of a code formatter. It's surgical: pick which whitespace problems to fix and leave everything else exactly as it was. Trim trailing whitespace per line. Collapse multi-spaces. Remove blank lines. Normalize line endings. Each rule is independent.

The four most common problems

Trailing whitespace. Every line that ends with extra spaces. Invisible in most viewers but breaks YAML, breaks markdown tables, and shows up as "changed" lines in Git diffs even when nothing visible changed. Fix: turn on "Trim per-line."

Double spaces. Old typography habit (two spaces after a period) that survived into the digital era. Modern style guides use single spaces. Auto-collapse helps when you're cleaning up text written by someone with the old habit. Fix: turn on "Collapse multi-space."

Blank lines that shouldn't exist. Three blank lines between paragraphs when one is enough. Five blank lines between sections when one is intended. Most markdown editors render any number of blank lines as a single paragraph break, so the extras are noise. Fix: turn on "Collapse blank lines" (keeps one) or "Remove blank lines" (kills all).

Mixed line endings. Unix and modern macOS use \\n (LF). Windows uses \\r\\n (CRLF). When files of different origins mix in one document, Git, sed, and shell scripts get confused. Fix: pick LF or CRLF and let the tool normalize the whole document.

Trim, collapse, remove: pick the right verb

Trim removes whitespace from the edges of a line. " hello world " becomes "hello world". Always safe.

Collapse replaces runs of spaces with a single space. "hello world" becomes "hello world". Safe for prose, sometimes wrong for code that uses spaces for alignment.

Remove ALL spaces is rare. It collapses every space, internal or edge, into nothing. "hello world" becomes "helloworld". Useful when concatenating identifiers or stripping spaces from numeric strings ("1 234 567" becomes "1234567"). Almost never useful for prose.

Tabs vs spaces, the eternal debate, briefly

This tool has both options. Strip tabs removes them entirely. Tabs to spaces replaces each tab with N spaces (your choice: 2, 4, or 8 are common). Use the latter when pasting code from one editor into another with different tab settings.

The tab-vs-space debate is settled by your team's style guide, not by us. Both work. Most modern languages and editors lean toward 2 spaces. Python officially recommends 4 spaces. Go uses tabs. Use what matches the surrounding code.

Why "preserve" line endings exists

The tool offers a third line-ending option called "preserve," which best-effort detects whether the input is mostly LF or mostly CRLF and uses that style for the output. It's the safe default when you don't care which style; you just want the document internally consistent.

If you're targeting a specific platform, pick LF (Unix, macOS, web) or CRLF (Windows-only files) explicitly.

Invisible Unicode whitespace is real

Beyond the standard space and tab, Unicode defines a whole zoo of "whitespace" characters: non-breaking space (U+00A0), zero-width space (U+200B), ideographic space (U+3000), and many more. They're invisible in most editors and they almost always cause bugs.

The "Trim per-line" option uses JavaScript's \\s class, which catches non-breaking spaces, zero-width spaces, and most Unicode whitespace. So pasting from word processors, PDFs, or web pages tends to clean up automatically along with the visible whitespace.

When NOT to clean whitespace

Two cases:

Whitespace-sensitive formats. YAML, Python, Makefile, and certain command outputs depend on exact indentation. Don't run aggressive whitespace cleanup on these. Use only "Trim per-line" (which only touches edges) and never "Collapse multi-space" (which would break alignment).

Code with intentional alignment. Some teams align operator runs in source code (a = 1, bb = 2, ccc = 3). Collapsing spaces destroys the alignment. If you preserve that style, leave Collapse off.

For everything else: prose drafts, CSV cells, log lines, JSON pasted from somewhere weird, the default settings on this tool (trim, collapse multi-space, collapse blank lines, trim document edges) cover the 90% case.