VS Code removes whitespace through two built-in commands: Trim Trailing Whitespace strips spaces and tabs at the end of every line, and Delete Horizontal Whitespace (Ctrl+J on Windows and Linux, Cmd+J on macOS) collapses any run of consecutive spaces, tabs, and other horizontal whitespace on the current line into a single space. Both commands live in the Command Palette (Ctrl+Shift+P) and can be triggered by shortcut, menu, or settings file. For predictable, repeatable transformations where you want to see exactly what will happen to your text before committing to a change, a browser-based tool with explicit modes is often a more controlled option. The Whitespace Remover tool runs entirely in your current tab, gives you three deliberately different modes to choose from, and reports the exact output length in JavaScript UTF-16 code units so you can verify the change before copying. This guide walks through both the VS Code built-in route and the browser tool, with a clear-eyed look at when each one is the better fit.

Remove Whitespace in VS Code with Built-In Commands
VS Code exposes whitespace cleanup through the Command Palette and through user settings. The commands are documented under both the editor and files namespaces, and each one targets a different part of the problem. Trailing whitespace is the most common offender because it inflates diffs and trips linters, while runs of horizontal whitespace inside a line are usually just copy-paste artifacts from a browser, a chat client, or a poorly formatted email.
- Open the Command Palette with Ctrl+Shift+P on Windows or Linux, or Cmd+Shift+P on macOS.
- Type "Trim Trailing Whitespace" and press Enter to strip spaces and tabs from the end of every line in the active editor.
- Type "Delete Horizontal Whitespace" and press Enter (or use the default Ctrl+J / Cmd+J shortcut) to collapse any run of horizontal whitespace on the current line into a single space.
- To run Trim Trailing Whitespace automatically when you save, open settings.json and add "files.trimTrailingWhitespace": true.
- To keep the editor visually tidy without deleting whitespace, set "editor.trimAutoWhitespace": true so that selecting and typing replaces runs of spaces with a single space.
These commands operate on the active file. There is no single built-in command that removes every whitespace character across the whole file in one click, and there is no built-in command that strips blank lines without an extension. For those operations, an external tool with explicit modes is usually the safer choice because it lets you preview the result before you paste it back into your source.
When a Browser Tool Is the Right Choice
The built-in commands are fast and never leave your editor, but they have real limits. They do not count what they removed, they do not preview the output on a separate buffer, and they do not give you a choice between "collapse horizontal whitespace" and "remove every whitespace character" — those are different operations that can produce dramatically different output. If you are cleaning prose for a content management system, normalizing a list copied from a spreadsheet, or preparing compact token input for a script, the difference matters.
A browser tool is also useful when you want to clean text outside an active project without opening one. Paste the text, pick the mode that matches your downstream format, run the transformation, inspect the output, and copy. The Whitespace Remover does exactly this. It runs locally in the current tab, so no text is sent to a server, and it shows the exact length of the cleaned output so you can confirm the change before using it.
How to Remove Whitespace with the Whitespace Remover
The tool has three explicit modes and a stable three-step workflow. Choose the mode that matches your downstream format, then run the transformation.
- Paste or type the plain text you want to clean into the input area.
- Choose the mode that matches your goal: collapse horizontal whitespace for prose, trim lines and remove blank lines for lists and logs, or remove every whitespace character for compact tokens.
- Select Clean text, review the output and the reported code-unit count, then copy the result.
Changing the input or the mode clears the previous output, so the result you copy is always the one produced by the current settings. If the browser blocks clipboard access, the page leaves the full read-only result visible so you can select it manually — copying is a convenience rather than a hidden dependency on the clipboard API.
The Three Whitespace Remover Modes Compared
Each mode is a deliberate trade-off. The table below summarizes what each one changes and what it leaves alone, so you can pick the one that matches your downstream format before you run it.
| Mode | What it removes | What it preserves | Best for | Watch out for |
|---|---|---|---|---|
| Collapse horizontal whitespace | Runs of spaces, tabs, and other horizontal whitespace on each line; spaces directly beside line breaks; CRLF line endings (normalized to LF) | Line breaks and blank lines between paragraphs | Prose, articles, README content, paragraph text | Not a word-spacing normalizer; internal spacing inside paragraphs is reduced to single spaces |
| Trim lines and remove blank lines | Leading and trailing whitespace on each line; lines that become empty after trimming | Internal spacing inside non-empty lines; one LF line break between kept lines | Lists, copied tables, logs, pasted notes, CSV-like data | Does not collapse runs of spaces inside a line; intentional indentation is dropped |
| Remove every whitespace character | Every character matched by JavaScript's Unicode-aware whitespace class, including spaces, tabs, line breaks, and non-breaking spaces | Nothing — all whitespace is removed | Tight token input, compact machine-readable data, joining identifiers | Words and records can become adjacent; intended for tokens, not prose |
What the Counts Mean and What They Don't
The result panel reports two numbers: how many code units were removed and the final output length. Both are JavaScript UTF-16 code-unit counts for the exact input and output strings. A code-unit count is deterministic for the exact input, but it is not the same thing as a grapheme count, a visible character count, a byte count, or a word count. Emoji and some historic scripts can use more than one UTF-16 code unit, so a string with a flag emoji may show a higher code-unit count than a sighted reader would expect.
For a quick sanity check, take the input "Hello World\n\nFoo Bar" (22 code units). After Collapse horizontal whitespace, the result is "Hello World\n\nFoo Bar" (20 code units). The arithmetic is straightforward: 22 code units in, 20 code units out, so 2 code units were removed. The tool is deterministic, so the same input and the same mode always produce the same string.
Limits and Caveats for Code and Structured Data
Whitespace can be data. In Python, YAML, and Makefiles, indentation is part of the syntax. In Markdown, two trailing spaces on a line mean a hard line break. In CSV, a tab inside a quoted field is part of the value, not decoration. The Whitespace Remover does not parse any of these formats, so it will not warn you if a transformation breaks the structure. For source code, legal text, poetry, fixed-width data, YAML, Python, or any syntax where indentation and line endings carry meaning, preview the output in the result panel before copying, or use a format-aware editor.
When line breaks themselves are the only issue, the dedicated line-break remover is a more focused option: it standardizes line endings without touching other whitespace, so it leaves meaningful indentation alone. The Whitespace Remover does not perform automatic spelling, punctuation, Unicode normalization, HTML parsing, Markdown parsing, smart-quote conversion, de-duplication, or case conversion, and it does not preserve rich-text styling from a clipboard because the input is plain text. If you paste styled text from a word processor, only the textual content is processed.