To remove whitespace in Notepad++, open the Replace dialog with Ctrl+H, enable Regular expression mode, and run a pattern that matches the specific kind of whitespace you want gone — `\s+` for runs of any whitespace, `^\s+|\s+$` for line ends, `^\s+` for line starts, or `(?m)^\s*$` for empty lines. Each regex recipe solves a slightly different problem, and mixing them up is how people end up with collapsed code or stuck-together words. Notepad++'s built-in regex engine handles all four jobs without an extension, but the trade-off is that the result depends entirely on which pattern you typed and which boxes you ticked. That ambiguity is why many readers end up here after one too many failed replacements: the program ran, the dialog said "Replaced X occurrences," and the document still looks wrong. The safer approach is to be explicit about which kind of whitespace you want removed before you run anything, and to verify the output with a count rather than a glance. A browser-based cleaner with three labelled transformations makes the same idea easier to get right the first time.

how to remove whitespace in notepad++
How to Remove Whitespace in Notepad++ Without Breaking It

What Each Kind of Whitespace Does in Notepad++

Notepad++ treats whitespace as several distinct characters that behave differently inside text. Before choosing a regex, it helps to know which kind you are targeting, because the wrong pattern will silently do the wrong thing to the parts of the file you actually cared about.

A regular space (U+0020) is the most common character and is what most readers mean by "whitespace." A tab (U+0009) looks like a space on screen but is its own character, and a non-breaking space (U+00A0) is invisible to a casual reader and is the usual culprit behind text that "looks fine but won't sort." Line breaks add their own quirks: Windows files use CRLF (`\r\n`), Unix files use LF (`\n`), and old Mac files use CR (`\r`) alone. When you mix two of those conventions in the same document, the visible result looks fine but downstream tools can choke on the stray carriage returns.

Here is a quick recipe table for the most common Notepad++ jobs. Run these in the Replace dialog (Ctrl+H) with Regular expression mode checked. The Replace with field stays empty unless noted.

Goal Find pattern Replace with Side effect to watch
Collapse runs of horizontal whitespace into one space \h+ one space Does not touch line breaks
Remove spaces and tabs at the start of every line ^\h+ (empty) Indented source code becomes invalid
Remove spaces and tabs at the end of every line \h+$ (empty) Trailing whitespace often signals an incomplete edit
Remove every blank or whitespace-only line (?m)^\s*$ (empty) Leaves a blank line behind on each match; run twice
Strip every whitespace character including line breaks \s+ (empty) Joins all words and lines into one block

Note that `\h` in Notepad++ matches only horizontal whitespace (spaces and tabs), which is safer than `\s` when you want to preserve paragraph breaks. `\s` matches any whitespace including line breaks, so a careless `\s+` replacement is the single most common way readers flatten their document into one unreadable line and lose the paragraphs they meant to keep.

Three Modes for the Same Job in Your Browser

The five regex recipes in the previous section map almost one-to-one onto the three modes in the browser-based Whitespace Remover, which is worth opening in a second tab while you work. Where Notepad++ relies on you to type the right pattern and to remember what each character class actually matches, the tool labels its modes in plain English and shows the count of removed code units next to the output so you can confirm the change at a glance.

The three modes are deliberate rather than overlapping, and each one is built around a specific job:

Mode What it removes When it is the right choice
Collapse horizontal whitespace Runs of spaces and tabs on each line, spaces beside line breaks, CRLF normalized to LF; result trimmed Prose, paragraphs, blog posts, and email drafts
Trim lines and remove blank lines Leading and trailing whitespace on every line, then drops lines that become empty; rejoins with one LF Lists, copied tables, log excerpts, and pasted notes
Remove every whitespace character Anything matched by JavaScript's Unicode-aware whitespace class, including non-breaking spaces Tight token compaction, machine input, single-line IDs

If the regex table above feels like a lot to memorize, the tool is the easier version of the same idea. Paste your text, pick the mode that matches your downstream format, and the result panel reports how many JavaScript UTF-16 code units were removed from the exact input you supplied.

Cleaning Whitespace With the Whitespace Remover

Open the Whitespace Remover and run the four steps below to clean a chunk of pasted text without writing a regex by hand.

  1. Paste or type the plain text you want to clean into the input area. The text stays in your browser tab; nothing is uploaded to a server.
  2. Pick the mode that matches your goal: Collapse horizontal whitespace for prose, Trim lines and remove blank lines for lists, or Remove every whitespace character for compact tokens.
  3. Select Clean text. The tool runs the transformation locally and shows the exact output alongside the number of code units removed.
  4. Review the output, confirm the count is what you expected, then copy the result to your clipboard. If the browser blocks clipboard permission, the page reports that and leaves the read-only result visible for manual selection.

The result panel reports the number of removed code units as the difference between the input length and the output length. That number is deterministic for the exact input string and the chosen mode: paste the same text with the same mode twice and you get the same string, which is the property that lets you trust the count as a verification rather than a guess.

Counting Code Units vs Visible Characters

The counts the tool reports are JavaScript UTF-16 code units, not bytes, graphemes, or word counts. For plain ASCII text the three numbers usually agree, but for emoji, accented letters, and CJK characters they can drift. The same input and the same mode always produce the same string, so the difference between input length and output length is a stable number you can rely on when you want to confirm a transformation did exactly what you asked.

A short worked example shows what the count means in practice. Take the input string " Hello World " with input length 18 UTF-16 code units. With Collapse horizontal whitespace, the leading 2 spaces and the trailing 2 spaces are trimmed from the complete result, and the run of 4 internal spaces is collapsed to 1. The output is "Hello World" with output length 11, so the tool reports 7 code units removed (18 minus 11). The number is deterministic: paste the same string into the same mode and you get the same output with the same code-unit count every time.

Emoji and some historic scripts can use more than one UTF-16 code unit per visible character, so a longer-looking emoji string can still report a smaller removed count than a shorter-looking ASCII string. The tool does not pretend otherwise; the count is always the JavaScript string length of the exact input and output.

When Each Mode Helps, and When It Hurts

Each mode exists because there is a real job it does well, and a real job it ruins. The safest pairing is Collapse horizontal whitespace for anything that will be read by a human: paragraphs, blog drafts, email replies, product descriptions. It preserves line breaks, so paragraphs stay separated, and it normalizes CRLF to LF so the cleaned output behaves the same on Windows, macOS, and Linux.

Trim lines and remove blank lines is the right choice for lists, copied tables, log excerpts, and any case where lines should not carry stray indentation. The mode is explicit about not touching internal spacing, so words inside a non-empty line stay exactly as you typed them. Run this mode when you have pasted something from a PDF or a console and you want the entries to line up without doing the cleanup by hand.

Remove every whitespace character is the destructive mode and earns that label by joining words that used to be separated. It is the right choice for tokens and tightly controlled machine input, such as concatenated IDs, single-line keys, or CSV values that have to fit on one line. It is the wrong choice for prose, code, YAML, or anything where a space carries meaning. If line breaks are the only issue you are fighting, the related Remove Line Breaks in Notepad++ Without a Regex Mistake guide covers a more focused option that targets breaks without touching other whitespace.

For source code, legal text, poetry, fixed-width data, YAML, Python, or any syntax where indentation and line endings carry meaning, preview the result carefully or switch to a format-aware editor. Whitespace can be data, and this is the case to remember that. The page leaves the final choice visible to the user rather than silently destroying the layout.

Why a Browser Cleaner Is Safer for Sensitive Text

If the document you are cleaning includes names, emails, internal notes, or anything else you would not paste into a random web form, the local-only path is worth taking. The Whitespace Remover runs the transformation in the current browser tab, which means the input text, the chosen mode, and the result never leave your machine. The result panel is read-only and shows the exact string that was produced, and the clipboard copy is a convenience rather than a hidden dependency: when the browser grants permission the tool confirms the copy, and when permission is blocked the page reports that condition and leaves the full result visible for manual selection.

The transformation is deterministic, which means the same input and the same mode always produce the same string. There is no AI rewriting, no spelling correction, no smart-quote conversion, and no automatic Markdown or HTML parsing. If the input contains non-breaking spaces, tabs, CRLF line endings, or any other character matched by JavaScript's Unicode-aware whitespace class, the relevant mode will treat them the way the regex expects; if the input does not contain them, nothing happens to that part of the text. The Unicode-aware behavior follows the rules documented in MDN's character class escapes reference, and the underlying replace operation follows the rules in MDN's String.replace reference, which keeps the behavior predictable across runs and across browsers.

For very large files, paste in chunks so the result panel stays easy to read. For any input you cannot afford to misread, change the mode and watch the output panel reset before you copy: the tool clears stale output when you change the input or the mode, which is the small detail that stops a copied result from being mistaken for the current settings.

For a deeper look, see Remove Word Wrap and Re-wrap at a New Column Width.