CruxDevCruxDev Tools Prompts
text Utility • Zero-Server Privacy • 100% Client-Side

Whitespace Trimmer

Remove leading, trailing, and duplicate internal spaces from any text block.

Overview

Seven whitespace operations in one panel: trim the ends, collapse every run of invisible characters to a single space, delete all whitespace, strip blank lines, swap tabs for spaces or spaces for tabs, and normalise Windows line endings. It is Unicode-aware where it matters — a non-breaking space pasted from a rich-text editor counts as whitespace here, and the tool tells you so.

How It Works

Paste text into the input box, then pick an operation from the segmented control: Trim ends, Collapse runs, Remove all, Strip blank lines, Tabs to spaces, Spaces to tabs or CRLF to LF. The output updates live and a Characters-removed counter quantifies what the operation deleted. Each mode shows a one-line explanation of exactly what it does, including its edge cases, so the behaviour is documented on the page rather than discovered by experiment.

Step-by-Step Usage Guide

  1. Paste the text into the input box.
  2. Choose an operation; the result and the characters-removed count update immediately.
  3. For prose that will be re-wrapped, use Collapse runs; for identifiers and codes, use Remove all.
  4. Copy the cleaned text, or re-run a second operation on the result if the job needs two passes.

Technical Specifications & Standards

Whitespace looks like a solved problem until text arrives from Word, a PDF or a web form. JavaScript's \s class — which this tool uses everywhere — matches more than the spacebar: it also matches the non-breaking space U+00A0, the narrow non-breaking space U+202F, the ideographic space U+3000, the line and paragraph separators U+2028/U+2029, the byte-order mark U+FEFF, and of course tabs, newlines and carriage returns. All of these were verified directly in the engine this site runs on. Two consequences matter. First, Remove all genuinely removes invisible junk: a run of “a\u00A0b” — which looks like normal text with a space — loses its non-breaking space along with the real ones. Second, one character escapes: the zero-width space U+200B is not whitespace in JavaScript's classification, it is a format character, so Remove all leaves it in place and Strip blank lines does not count a line containing only it as blank. That distinction is a trap in the other direction: text that looks empty but contains U+200B will still trip comparisons. The two tab modes use a width of four, the common convention in web code; Spaces to tabs deliberately converts only exact four-space runs, so a three-space indent is left alone rather than guessed at. Line-ending normalisation rewrites CRLF and bare CR to LF, which is the shape diff tools, linters and Unix-oriented pipelines expect — a file edited across Windows and macOS often ends up with both. The counter at the bottom reports the length difference, which is a quick way to notice, for example, that a “clean-looking” string just lost two hundred bytes of invisible padding.

Targeted Use Cases

  • Cleaning text pasted from Word, PDFs or web forms that carries non-breaking and other exotic spaces.
  • Normalising indentation and line endings before committing a config or data file.
  • Turning a multi-line block into a single-line string for a URL, CSV cell or command-line argument.
  • Stripping empty lines from logs or lists before counting or parsing them.

Notes & Gotchas

  • Use Collapse runs for human-readable text and Remove all only for identifiers — Remove all deletes newlines, so lines merge.
  • If the output still looks wrong after Remove all, suspect zero-width spaces: they are not whitespace in JavaScript and survive this tool by design.
  • Run CRLF to LF before diffing or version-controlling text that has been edited on more than one operating system.
  • Trust the character counter over your eyes; the whole point of this tool is that the interesting characters are invisible.

Frequently Asked Questions

Does the tool remove non-breaking spaces?

Yes. In JavaScript, \s matches U+00A0, so Trim, Collapse and Remove all all treat a non-breaking space exactly like a normal space. The same goes for the ideographic space and the narrow non-breaking space.

Why did Remove all leave something invisible behind?

Almost certainly a zero-width space, U+200B. JavaScript classifies it as a format character, not whitespace, so \s does not match it and the tool leaves it. Paste the result into the character counter if you need to hunt one down.

What is the difference between Trim ends and Collapse runs?

Trim ends removes whitespace only at the start and end and keeps interior spacing untouched. Collapse runs also squeezes every interior run of whitespace — including newlines — down to one space, which flattens the text to a single line.

Why do tabs convert to four spaces and not eight or two?

Four is the dominant indent width in web code and the least surprising default. If your standard is different, convert tabs to spaces first and adjust, or use Spaces to tabs, which groups exact four-space runs into one tab.