Normalizing whitespace: CRLF, tabs, trailing spaces

Published: 2026-09-05

How mixed line endings, tabs vs spaces, and trailing whitespace break diffs and reviews—and how to normalize them locally before you sort, dedupe, or commit.

Invisible characters cause visible pain. A file that “looks fine” can still fail a CI check, show every line as changed in a diff, or make two identical-looking strings fail equality. Most of that noise comes from three places: line endings (LF vs CRLF), tabs vs spaces, and trailing spaces at the end of a line.

LocalTools’ Whitespace normalizer fixes those three in the browser—paste, choose options, copy—without uploading the text.

Why whitespace shows up as “changes”

Symptom Usual cause
Diff paints the whole file red/green CRLF ↔ LF rewrite (or both styles mixed)
Indentation jumps when you open another editor Tabs rendered at a different width than the author used
“Same” lines fail string equality or dedupe Trailing spaces/tabs on one copy only
git blame / review noise Editor auto-stripped trailing spaces on save for some files

Treat whitespace cleanup as a first pass before sorting or deduping lines, batch find/replace, or a careful text diff.

Line endings: LF vs CRLF

Historically:

  • LF (\n) — Unix, macOS, most tooling and Git defaults on those platforms
  • CRLF (\r\n) — classic Windows text files and some legacy protocols

Modern Git often normalizes on checkout (core.autocrlf / .gitattributes), but pastes from email, Excel, or Windows Notepad still arrive as CRLF—or worse, a mix. Splitting must treat LF, CR, and CRLF as line breaks; joining should emit one chosen style so the output is consistent.

In the normalizer, pick LF or CRLF for the output. A trailing newline on the paste is preserved when present (same convention as the sort/dedupe tools).

Practical rule: prefer LF for source code and configs shared across OSes unless a format or team standard requires CRLF (for example some Windows-only scripts).

Tabs and spaces

A tab is one character; how wide it looks depends on the editor’s tab stop (commonly 2, 4, or 8 columns). That is why “same indent” can look different after a copy-paste between tools.

The normalizer offers three modes:

Mode What it does When to use
Leave tabs as-is Only line endings / trailing strip apply You already agree on tabs, or you only care about CRLF
Expand tabs → spaces Each tab becomes spaces to the next fixed stop from column 0 Align with space-indented codebases and many linters
Leading spaces → tabs Full tabWidth groups of leading spaces become tabs; remainder stays spaces Convert soft-indent pastes into tab-indented style

Important details that match real editor behavior:

  • Expansion uses fixed stops from column 0, not “always insert N spaces per tab.”
  • Leading-spaces-to-tabs only touches spaces before the first non-space—it does not rewrite spaces inside the line.
  • Tab width is clamped to a small practical range (typical values: 2, 4, 8).

Operations run per line, top to bottom: tab/space conversion first (if enabled), then optional trailing strip.

Trailing spaces and tabs

Trailing ASCII spaces and tabs are easy to introduce (wrap paste, export, accidental Space at EOL) and hard to see. They break:

  • Exact line match in Dedupe lines ("alpha ""alpha")
  • Hash or checksum comparisons
  • Some “no trailing whitespace” CI rules

Stripping removes only ASCII space and tab at line ends—not other Unicode spaces (narrow no-break space, em space, and so on). If you still see invisible oddities after a strip, inspect with a hex or Unicode-aware viewer, or use Find & replace for specific characters.

The tool does not trim leading indentation except via the optional leading-spaces-to-tabs mode. That is intentional: bulk-deleting indent would destroy code structure.

A sensible cleanup workflow

  1. Paste the noisy block into Whitespace normalizer.
  2. Choose LF or CRLF for the project’s convention.
  3. Expand tabs to spaces (or the reverse) only if your style guide says so; otherwise leave tabs alone.
  4. Enable strip trailing spaces & tabs.
  5. Copy the result. Check the live stats (how many lines lost trailing whitespace; how many tab transforms touched).
  6. Continue with Sort / Dedupe, Find & replace, or Diff Checker if you need a before/after review.

For word counts and reading-time after cleanup, use Text statistics.

Why normalize locally

Logs, customer lists, and unreleased configs should not leave the machine for a “quick CRLF fixer.” Whitespace normalization on LocalTools stays in the tab—same local-only model as the rest of the site.

Try it locally

Open Whitespace normalizer, paste mixed endings or tab-indented text, pick LF/CRLF and a tab mode, toggle trailing strip, then copy. Nothing is uploaded.

Related reading

All learn articles