Whitespace Remover
Remove extra spaces, tabs, blank lines, and invisible characters from text - trim, collapse, or strip all whitespace in your browser.
- Free, no account
- No watermark
- No usage limit
About the Whitespace Remover
The spaces you can see are rarely what breaks things. The ones that wreck a string match or a password field are the ones you can't, a non-breaking space, a zero-width character, a byte-order mark that rode along when you copied text out of a web page, a PDF, or a Word doc. They show up as an ordinary gap on screen, or as nothing at all, and they sit inside your text looking perfectly innocent. Drop that text in here and the Strip invisible characters switch goes straight after that layer, the stuff a plain trim walks right past. The everyday cleanups are here too: trim the ragged edges off each line, fold runs of double and triple spaces down to one, delete blank lines, or remove every space so the whole thing fuses into one string. It all runs in your browser, nothing you paste is uploaded or logged, and that's exactly why it's safe to clean a password, an API key, or a private snippet without it ever leaving your machine.
Most quick whitespace cleaners only know the visible family, spaces, tabs, line breaks, and that's the easy half to handle. The zero-width characters are the half that actually causes trouble, and plenty of tools skip them completely, because a zero-width space or a soft hyphen isn't even classified as whitespace, so a "strip all spaces" pass steps right over it. You can run the same messy text through three different cleaners and still end up with two values that read as identical yet refuse to match. This one puts the invisible stuff in its own category and deletes it on request, and it turns the non-breaking space into a regular space first so the collapse step can then fold it in. Live before/after counts sit under the boxes, so you can watch how many characters, and how much actual whitespace, came out.
How to use
- Paste your text into the Input box. The cleaned version appears below and updates the moment you type, paste, or flip a switch, so there's no button to press.
- Leave the default cleanups on for a normal paste mess. Trim each line, collapse multiple spaces and tabs, trim the whole block, and strip invisible characters all start on, because that combination fixes the most common junk without changing the shape of your text.
- Keep Strip invisible characters on whenever the text came from the web, a PDF, or a rich-text editor. It's on by default, and it's the one that catches non-breaking spaces, zero-width characters, and the byte-order mark a plain trim leaves sitting there.
- Reach for Remove ALL whitespace only when you want a single unbroken string with every space, tab, and line break gone. It overrides the other switches, since there's nothing left for them to do.
- Copy or clear. "Copy result" grabs the output, "Clear" empties the box and starts you fresh.
The whitespace you can't see, and why it wins
The text looks clean, so when something downstream falls over, whitespace is the last thing anyone checks. A trailing space turns "John" into "John " and your deduplication quietly keeps both copies. A non-breaking space wedged into 1 000 stops it parsing as a number, and the import rejects the row with an error that points nowhere near the real cause. You paste an API key out of an email, it fails with a flat "invalid credentials", and you burn twenty minutes sure you fat-fingered it, when really a non-breaking space came in with the copy. Slip a zero-width space into the middle of a value and two strings that render exactly the same on screen will never compare equal, and you'll sit there swearing they're identical.
The cure is the same every time. Normalize before you trust the string, strip the invisible members out or turn them into ordinary spaces, trim the edges, then compare clean against clean. That's the job this tool is really built for, and it's why the invisible switch is kept separate from the rest. You can strip the hidden characters without collapsing anything else, or stack both, depending on what actually went wrong. The counter is your proof: run a value you think is spotless through the tool, and if the "before" whitespace number is higher than the visible spaces you can count, there's an invisible one hiding in there.
Picking the right switch (and not over-cleaning)
Each cleanup is its own toggle for a real reason. They do genuinely different jobs, and the right one depends entirely on what you're about to do with the text next.
Collapse is the gentle one. It squashes runs of spaces and tabs down to a single space and leaves your line breaks alone, so a paragraph pulled out of a PDF with every word double-spaced comes back readable. Remove ALL whitespace is the far end of the scale, it deletes everything and welds the characters together, which is right for compacting a value or reassembling a serial number that got wrapped across two lines, and wrong for anything a person actually reads.
Code is where you slow down, because there whitespace often carries meaning and the wrong switch changes how the file behaves, not just how it looks. Remove blank lines is the safe one, it never touches indentation. Trim each line is riskier, leading whitespace is your indentation, so in Python or YAML it will break the file. Collapse flattens aligned columns and multi-space indents. Remove ALL flattens structure altogether. So the rule of thumb is simple: on prose, be as aggressive as you like, on code, start with the gentlest switch that fixes your real problem and eyeball the output before you rely on it. And if the result ever looks too flat, collapse is usually the one that changed the shape, so turn that off first.
Frequently asked questions
Why do two strings that look identical still fail to compare?
Almost always an invisible character hiding inside one of them, and the counter here is the fastest way to catch it. Paste each value in on its own and read the "before" whitespace number. If a value you swear is clean reports whitespace you can't see, a trailing space, a non-breaking space, or a zero-width character is riding along. Strip the invisible characters (or remove all whitespace) on both, and if they match now, that was your culprit the whole time.
It stripped my non-breaking spaces but left a space behind. Why?
That's on purpose. Strip invisible characters converts a non-breaking space into a regular space rather than deleting it, so the collapse step can then fold it in with its neighbors like any other gap. Truly zero-width things (the zero-width space, the byte-order mark) have no width to preserve, so those get deleted outright. If you want the non-breaking space gone entirely with nothing in its place, run Remove ALL whitespace instead, which sweeps every kind at once.
What's the safest way to clean pasted code?
Turn off Trim each line and Collapse, since both can eat indentation that matters, and keep Remove blank lines, Strip invisible characters, and Trim start/end of whole text. That combination drops empty lines, kills any hidden characters your editor smuggled in, and tidies the very top and bottom of the block, all without touching a single leading space inside your lines. Then read the output before you paste it back. Whitespace-sensitive languages punish a wrong guess.
Can I remove the invisible characters without changing anything else?
Yes. Switch off Trim each line, Collapse, Remove blank lines, and Trim whole, and leave only Strip invisible characters on. The tool will delete the zero-width and format characters and normalize the non-breaking spaces, and it won't reflow your text or fold any of your visible spacing. It's the right setting when the layout is already fine and you only need the hidden gremlins gone.
Is my text uploaded to a server?
No. Every bit of the cleaning happens on your own device, so your text is never uploaded, saved, or logged. Close the tab and whatever you pasted is gone with it. That's the reason it's fine for passwords, tokens, and private data that you would never want to hand to some random website's backend.
Is there a size limit on what I can paste?
No fixed cap. Because the work runs locally, you can throw anything at it from a single line to a very large document. A huge paste might take a beat since your device is doing the work, but nothing gets truncated or sent anywhere.
Does it handle Windows and Mac line endings?
Yes. It recognizes Windows \r\n, old Mac \r, and Unix \n, and treats them the same, so Remove blank lines and Remove ALL whitespace behave identically whatever system the text came from. The Unicode line separator that Word and a lot of PDF extractors emit counts as a break here too, which matters because most cleaners delete it and weld your two lines into one. Worth knowing about the output: once any of the per-line options run, the result comes back with plain \n endings, so a Windows file goes in with \r\n and comes out without it.