Normalize spaces, tabs, and line endings in text

Normalize line endings, tabs, ordinary-space runs, and edge whitespace in pasted prose.

freeworks offlinenothing uploaded
ToolWhitespace Cleaner
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

CRLF and CR become LF, each tab becomes a fixed number of spaces, every row is trimmed, runs of two or more U+0020 spaces collapse to one, and the document is trimmed. The removal statistic compares JavaScript string lengths and adjusts for tab expansion.

  • Four spaces per tab matches a common editor setting, while all cleanup stages start enabled for prose rather than source code.
  • Each stage can be disabled because indentation-sensitive content must not use the destructive defaults.

Worked example

Clean up messy whitespace
Normalize tabs, multiple spaces, and line endings
Input
											hello   world		foo
  bar  
										
Output
												hello world foo
bar
											

When to use this

Rich-text paste cleanup removes repeated spacing, cross-platform fixtures normalize line endings, and tab-separated prose is flattened after its columns are no longer needed.

Edge cases

  • Leading code indentation disappears because tabs expand before each line is trimmed.
  • An internal U+00A0 non-breaking space is not collapsed by the ordinary-space regular expression.
  • A tab becomes four fixed spaces rather than advancing to a tab stop, so an aligned table can shift.

References