By · Updated

Remove Extra Spaces From Text

Remove Trailing Spaces, Blank Lines and Zero-Width Characters From Text

No ratings yet

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the Whitespace Cleaner works

This tool will remove extra spaces from text and invisible characters too. Paste text that has been through a word processor, a PDF or three rounds of email and get it back clean: double spaces collapsed, trailing spaces gone, blank lines tidied and invisible Unicode characters replaced with ordinary ones. Everything happens in your browser.

Whitespace cleaner: the problems you cannot see

Whitespace problems are invisible by definition, which is why they survive so long. Text copied out of a PDF, a Word document or a rendered web page routinely carries characters that look exactly like a space and behave nothing like one.

Remove extra spaces from text

The double space after a full stop is a typewriter convention that survives in text written by anyone who learned to type before about 1990. HTML collapses runs of whitespace when rendering, so the problem hides on a web page and reappears the moment the text is used anywhere else — a plain-text email, a CSV field, a database column, a search index.

Remove trailing whitespace

Spaces at the end of a line are the most common cause of unexplained differences between two apparently identical strings. They break exact-match comparisons, show up as noise in every line of a diff, and in Markdown two trailing spaces are a hard line break, which means a stray pair can change how a document renders.

Leading whitespace is different

Indentation is meaningful in code, in YAML and in anything where the shape carries information, so stripping it is off by default. Turn it on for prose pasted out of a document, where the indentation is a leftover from the original layout rather than structure you want to keep.

Remove zero-width characters and no-break spaces

A no-break space looks identical to a space and never breaks a line, which is why it silently breaks text wrapping when pasted into a narrow column. Word processors insert them automatically. The zero-width space, joiner and non-joiner have no width at all, so a word containing one appears normal but fails every string comparison and every search. The byte-order mark at the start of a file is the same problem: an invisible character that makes the first field of a CSV mysteriously not match its own name. Replacing them is on by default because the text almost never wanted them.

Tabs

A tab is one character that renders at whatever width the viewer decides, which is why the same file looks aligned in one editor and ragged in another. Converting to spaces fixes the appearance permanently, at the cost of the reader's ability to choose their own indent width. For code, follow the project's convention; for pasted text, converting is usually right.

Delete blank lines, or collapse them

Collapsing runs of blank lines to a single one preserves paragraph breaks while removing the accumulated padding of several edits. Removing them all is right when the text is really a list. Keeping them all is right when the exact spacing matters — verse, a fixed-format record, or anything you intend to diff against an original.

Indent text online, and unindent it

Adding spaces to every line is the quick way to nest a pasted block inside a code sample, a YAML document or a Markdown list item. Removing them takes at most that many spaces off the front of each line, so a block with mixed depth keeps its relative shape, and blank lines are left alone rather than being padded with trailing spaces.

Convert CRLF to LF

Windows ends a line with a carriage return and a newline; Unix, macOS and the web use a newline alone. Editors mostly hide the difference, but Git shows every line as changed when the two are mixed, and shell scripts with CRLF endings fail with a baffling \r: command not found. Whatever mixture comes in, the output uses one style throughout.

Order of operations

Invisible characters are normalised first, then tabs, then the per-line tidying, then blank lines. That order matters: a line containing only a no-break space is not blank until the character has been replaced, and would otherwise survive a blank-line removal pass looking like an empty line that refuses to disappear.

The characters this tool replaces

Character Code point Looks like What it does to your text
No-break space U+00A0 A space Refuses to wrap; fails a match against a real space
Zero-width space U+200B Nothing Breaks search and equality inside a word
Zero-width non-joiner U+200C Nothing Same, plus it changes ligature rendering
Zero-width joiner U+200D Nothing Same; legitimate only inside emoji sequences
Byte-order mark U+FEFF Nothing Makes the first CSV column name not match itself
Tab U+0009 Any width Aligns in one editor and not another
Carriage return U+000D Nothing Shows every line changed in Git; breaks shell scripts

Which options to turn on

Text came from Turn on
A PDF or Word document Repeated spaces, invisibles, trailing, leading
A web page Invisibles, repeated spaces, blank lines
A Windows file for a Unix server Line endings to LF
A chat export or list Trailing, remove all blank lines
Source code Trailing, tabs per project rules; leave leading alone

FAQ

Why does my text have invisible characters in it?

Word processors insert no-break spaces automatically, PDFs use them for justification, and copy-pasting from a web page can bring zero-width characters along. They look like ordinary spaces or like nothing at all, but they are different characters and fail every exact match.

What is a zero-width space and why does it break things?

A Unicode character with no visible width, used to mark a permitted line-break point. A word containing one looks completely normal but is a different string from the same word without it, so searches, comparisons and deduplication all quietly fail on it.

Should I strip leading whitespace?

Not for code, YAML, or anything where indentation carries meaning — that is why it is off by default. Turn it on for prose pasted out of a document, where the indent is a leftover from the original layout rather than structure worth keeping.

Why does trailing whitespace matter if I cannot see it?

It breaks exact string comparison, adds noise to every diff, and in Markdown two trailing spaces mean a hard line break, so an accidental pair changes how the document renders. Most editors strip it on save for exactly these reasons.

How do I convert CRLF to LF?

Set the line endings to LF and every line, whichever style it arrived in, goes out with a plain newline. Choose CRLF for the reverse. Mixed input is fine — the text is split on any ending and rejoined with the one you asked for.

Should I collapse or remove blank lines?

Collapse when the text is prose and the blank lines separate paragraphs — you keep the structure and lose the padding. Remove all when the text is really a list. Keep all when the exact spacing is part of the content and you plan to compare against the original.

How do I remove double spaces after full stops?

Turn on repeated spaces. Every run of two or more spaces between text collapses to one, including the pairs after full stops. Indentation at the start of a line is left alone, so code keeps its shape; strip leading whitespace separately if you want that gone too. If the text also has tab-aligned columns, convert tabs first so they are treated the same way.

Does it change the text inside code blocks or quotes?

No distinction is made; every option applies to every line. Paste only the block you want cleaned, or leave leading whitespace and tabs switched off when the text contains code whose indentation matters, and clean the prose around it separately.

See also: all Writing & Editing tools, Lists & Lines, Markdown & HTML, Ciphers & Alphabets.

Related tools