Whitespace Remover: Extra Spaces and Blank Lines
Remove extra spaces, blank lines, tabs and invisible characters from text in your browser. Trim lines, collapse spaces, normalise line endings. Nothing is uploaded.
Zero-width characters are deleted and non-breaking spaces become normal spaces.
Deletes every space, tab and line break. Overrides the other options.
0 characters, 0 bytes
0 characters, 0 bytes
About the Whitespace Remover
The Whitespace Remover cleans up text that has picked up extra spaces, stray tabs, blank lines and invisible characters. Paste the text, and the cleaned version appears beside it straight away, with a short note saying how many characters changed. By default it collapses repeated spaces, trims every line, trims the whole text and removes invisible characters. Every other switch is off until you turn it on. Your text stays in the page and never leaves your device.
How to use it
Steps
- Paste or type your text in the input box.
- Read the result in the output box. The note under it says
Removed 7 characters,Added 2 charactersorNo characters changed. - Switch options on or off to match what you need. The output updates as you click.
- Copy the cleaned text from the output box.
Where stray whitespace comes from
Text copied out of a PDF often carries a space at the end of every line and double spaces where columns used to be. Web pages bring non-breaking spaces that look like normal ones. Chat apps and word processors can add zero-width characters, and a file saved by some Windows editors starts with an invisible byte order mark. None of it shows on screen, but a program sees it. A CSV cell holding ID-204 with a trailing space will not match ID-204 in a lookup, a form may reject an email address with a space on the end, and an extra tab can break an indented line of code.
The options, in the order they run
1. Remove invisible characters (on)
Non-breaking spaces (U+00A0, U+202F and U+2007) become ordinary spaces, so the words around them stay apart. Zero-width space (U+200B), word joiner (U+2060) and the byte order mark (U+FEFF) are deleted. The zero-width joiner (U+200D) and zero-width non-joiner (U+200C) are kept on purpose, because emoji sequences and some scripts need them to display correctly.
2. Convert tabs to (Keep tabs)
Choose 2 spaces or 4 spaces to replace each tab. With Keep tabs, tabs are left alone. Because this step runs before collapsing, leave Collapse repeated spaces off if you want the new spaces to stay as indentation.
3. Collapse repeated spaces (on)
Any run of two or more spaces or tabs on a line becomes one space, so a b becomes a b. A single tab on its own is not touched here. Line breaks are never merged by this step.
4. Trim every line (on)
Removes spaces from the start and end of each line, so a becomes a.
5. Remove blank lines (off)
Deletes lines that are empty or hold only whitespace, so a, an empty line, a line of spaces and b become two lines. The /remove-blank-lines address opens this same page with the switch already on.
6. Trim the whole text (on)
Removes blank space and empty lines before the first word and after the last.
7. Normalise line endings to LF (off)
Windows files end lines with CRLF (\r\n), older Mac files with a lone CR, and Linux and macOS with LF (\n). With this switch off, each line keeps the ending it had. With it on, every CRLF and CR becomes LF.
Remove all whitespace (off)
Deletes every space, tab and line break, so a b\tc\n d becomes abcd. This replaces the other steps entirely, so whatever else is switched on is ignored. It is useful for phone numbers, card numbers and codes pasted with gaps in them. It removes the whitespace characters your browser recognises, which include non-breaking spaces and the byte order mark, but not the zero-width space.
Examples
Worked examples
a, three spaces,b, two tabs andcon one line, with Collapse repeated spaces on, becomesa b c.aandbon two lines, with Trim every line on, becomeaandb.a, an empty line, a line of spaces andb, with Remove blank lines on, becomeaandb.aandbseparated by a tab, with tabs converted to 4 spaces and collapsing off, becomea b, and the note readsAdded 3 characters.
Good to know
- The count in the note is the net change in characters, so a tab turned into four spaces counts as an addition of three.
- Letters, punctuation and the words themselves are never changed, only the spaces between them.
- Spaces inside quoted strings, code and Markdown are treated like any other, so check the result before pasting it back into code where spacing matters.
Related tools
To keep only the first copy of each line after cleaning, use the Duplicate Remover. The List Sorter trims and sorts lists in one pass. Change capitalisation with the Text Case Converter, or compare the text before and after with Text Diff.
Frequently asked questions
Why are there extra spaces in text I copied from a PDF or a web page?
PDFs store each line as positioned fragments, so copying often adds a trailing space per line and gaps where columns were. Web pages use non-breaking spaces for layout, and some chat apps insert zero-width characters. The defaults here fold, trim and strip these in one pass.
What is the difference between trimming a line and trimming the whole text?
Trimming every line removes spaces at the start and end of each line separately. Trimming the whole text removes blank space and empty lines only before the first word and after the last one, leaving the lines in the middle as they are.
Which invisible characters does it remove, and which does it keep?
It deletes the zero-width space (U+200B), the word joiner (U+2060) and the byte order mark (U+FEFF), and turns non-breaking spaces (U+00A0, U+202F, U+2007) into normal spaces. The zero-width joiner and non-joiner are kept, because emoji sequences and some scripts break without them.
Does it keep Windows CRLF line endings?
Yes, unless you ask otherwise. Each line keeps the ending it arrived with, so a CRLF file stays CRLF after cleaning. Turn on Normalise line endings to LF to convert every CRLF and lone CR to a single LF, which is what Linux and macOS tools expect.
How do I turn tabs into spaces without losing indentation?
Choose 2 spaces or 4 spaces under Convert tabs to, and switch off Collapse repeated spaces. Tabs are replaced before collapsing runs, so leaving collapse on would fold the new spaces into one. Turning off Trim every line also keeps leading indentation.
What does Remove all whitespace do to the other options?
It overrides them. Every space, tab and line break is deleted and none of the other steps run, so the result is one unbroken string. Zero-width spaces are not counted as whitespace by the browser, so turn off Remove all whitespace and use the invisible-characters option for those.
What does the Removed characters count in the note mean?
It is the net difference in characters between your input and the output, counting each character once. Removing five spaces reads Removed 5 characters. Turning tabs into spaces can make the output longer, in which case the note says Added instead.
Is the text I paste here uploaded anywhere?
No. The cleaning is a few string operations that run in your browser tab, so the text is not sent to a server or stored. That makes it reasonable for internal lists, customer records and code you would rather not paste into an online service.