Text
Whitespace & Trim Tools
Clean up excess whitespace: trim line edges, collapse repeated spaces, remove empty lines, convert tabs ↔ spaces.
Extra whitespace — at line edges, doubled up inside text, blank lines, mixed tabs and spaces — is rarely visible at a glance, but it often breaks string comparisons, parsing, or how code looks. This tool cleans up such issues with a set of targeted operations.
How to use it
- Trim: strip whitespace from the start and end of every line.
- Collapse: replace several consecutive spaces or blank lines with a single one.
- Tabs ↔ spaces: convert in either direction with a chosen number of spaces per tab.
Common uses
- Cleaning up text copied from a PDF or Word document, which often leaves extra spaces and invisible characters behind.
- Normalizing code indentation to one consistent style (spaces only or tabs only) before a commit.
- Debugging why two visually identical lines aren't equal when compared — often the cause is a hidden extra space or a non-breaking space.
Things to keep in mind
A non-breaking space ( , code point U+00A0) looks like a regular space but is a different character to a computer — strings containing it aren't equal to a regular space in comparisons.
Trimming line-edge whitespace doesn't touch spaces inside words or sentences — collapsing repeated internal spaces is a separate operation.
Article about this tool: Whitespace and invisible characters: the hidden cause of weird bugs
Frequently asked questions
What's the difference between trimming edges and collapsing repeated spaces?
Trimming edges only removes spaces at the start and end of each line, while collapsing repeated spaces replaces multiple consecutive spaces within a line with a single one, without touching the edges.
How are blank lines and tab/space conversion handled?
You can remove blank lines entirely or just collapse consecutive blank lines into one, and convert tabs to spaces or vice versa with a configurable tab width.
Is the pasted text sent to a server?
No, cleanup runs entirely in your browser in JavaScript, no data is transmitted elsewhere.
What are zero-width characters?
These are characters (zero-width space, zero-width joiner, and others) that take up no space on screen at all, yet are present in the text as distinct characters. They sometimes get copied in from certain websites and can silently break string comparison or search.
Why does a non-breaking space look like a regular space but behave differently?
A non-breaking space ( ) is visually identical to a regular space, but to a computer it's a different character — strings containing these two kinds of space are technically not equal in comparison, even if they look the same on screen.