๐Ÿ”ง TL3 Tools

โฃ Remove Extra Spaces

Written by Jane Smith ยท Reviewed by Alex Chen ยท July 24, 2026

Strip leading/trailing whitespace and collapse multiple spaces, tabs, and blank lines.

Input

Output

What This Tool Actually Fixes

Paste text that was copied out of a PDF, an email thread, or a spreadsheet and you usually get a mess: runs of spaces, stray tabs, and ragged whitespace at the edges that a database field or a configuration file will not accept. This page collapses every run of spaces and tabs into a single space, trims the very start and end of the whole text, and offers two checkboxes for line-level cleanup. Only horizontal whitespace is touched, so the line structure you typed stays exactly as it was.

What a Messy Pair of Lines Becomes

The shortest realistic case is a two-line string with three spaces between the words and two spaces stranded on the final line:

hello   world
  

The first pass finds the run of three spaces and replaces it with one, which leaves the second line holding a single leftover space. With both checkboxes left off, the closing trim step swallows that trailing space together with the line break itself, and the output panel shows:

hello world

Two spaces in, one space out, and the line boundary is gone from the result. The tool reports the change in the statistics line under the input box, where the original character count and the cleaned count sit side by side.

A Second Example With Tabs

Real pasted text usually mixes spaces and tabs. Take two lines copied from a spreadsheet cell that was dragged sideways during editing:

John\tSmith  
  New York

With both checkboxes off, the tab becomes a space, the doubled space after Smith becomes a single space, and the two leading spaces on the second line become one. The newline survives, so the output is still two lines, but each one is now tidy apart from a stray space at the end of the first line and one at the start of the second. Tick Trim leading/trailing spaces on each line and those disappear too, leaving exactly:

John Smith
New York

That single checkbox is what turns a serviceable cleanup into a result that passes a strict validator.

The Two-Character Expression That Does the Work

The whole transformation hangs on one regular expression: /[ \t]+/g. The character class between the square brackets matches any ordinary space or tab, the plus sign means one or more in a row, and the g flag makes the replacement sweep across the entire string. Five spaces, a tab, or a tab sandwiched between two spaces all behave identically, because each run is swapped for a single space. Newline characters are not part of the class, which is why paragraphs survive the pass intact. The operation is a single linear scan, so the time it takes grows with the length of the text and nothing else; a document of several thousand lines is processed in a few milliseconds.

What the Two Checkboxes Change

The option labeled Trim leading/trailing spaces on each line runs the trim method on every line after the collapse step. It is the right choice for pasted code, where a copied block often arrives with a uniform indent that the original file does not actually contain. The option labeled Remove blank lines drops any line that is empty or contains only whitespace; a line holding a single word survives. Both options run after the main collapse, so a line reduced to nothing but spaces can never sneak back through the filter. With the blank-line option on, a pasted table that arrived with a gap between every row becomes a tight block, and with the line-trim option on, quoted reply text keeps its quoted markers while shedding the padding that came with them.

The Final Trim and Where It Sits in a Cleanup

After the line-level options, a final trim call cleans the outer edges of the whole document. That is what turns a file ending with a stray newline and a tab into one that ends cleanly, which matters when the output is about to go into a field that counts characters or a validator that rejects trailing whitespace. In a typical sequence this page runs first, right after the text is pulled out of a document and before it goes into a form, an import, or a diff. Address fields exported from a CRM, product names pasted from a catalog, and SQL statements copied out of a chat window all follow the same path: normalize the spacing here, then paste the clean result where it needs to go.

Common Sources of the Whitespace Problem

PDF viewers are the most common culprit. When a PDF was set with proportional fonts and full justification, copying a paragraph drags along the alignment padding the renderer used, producing irregular runs of spaces that have nothing to do with the words. Email forwards add a second layer: quoted replies are indented one level per message in the chain, and clients that convert indentation to spaces can leave the quoted text visibly ragged. Spreadsheets contribute tabs and the cells' internal padding when a selection is copied as text instead of as a table. Chat applications that wrap long messages sometimes translate the wrap into a space plus a tab, which reads as a double gap when pasted. All of these arrive with the same symptom, and the same single pass fixes them.

Unicode Whitespace You Will Still See

One character reliably survives the pass: the non-breaking space, Unicode U+00A0. Word processors and web pages use it to keep words together and to keep a currency symbol glued to its number, and because it is neither an ASCII space nor a tab, the expression leaves it alone. If a pasted paragraph shows stubborn gaps, that is usually the culprit. A few related characters behave the same way: the thin space U+2009 used in French typography, the en space U+2002, and the ideographic space U+3000 that CJK typesetting inserts. When these appear, swap them for ordinary spaces in your editor before converting, or paste through a plain-text step first. This is the one real limitation of the tool, and it is worth knowing before the output goes somewhere that validates whitespace strictly.

When This Page Is the Wrong Tool

Indentation is data in a few important places, and this page destroys it. A Python script relies on leading whitespace to define blocks, so collapsing its indentation to single spaces changes the program's meaning. Markdown lists and code fences use indentation the same way, and YAML files treat it as structure. Tab-delimited data is a second casualty: a tab that separates fields becomes a space, merging two columns into one. If the text carries meaning in its spacing, clean it with a formatter for the format in question rather than here. When the goal is to join lines instead of tidying them, the remove-line-breaks page is the sibling that does that.

Performance and Safety Notes

Because the replacement is one linear pass, very large inputs are handled without difficulty, and nothing about the conversion depends on the number of lines. The page keeps no undo history, so copy the original text into a scratch file before converting; the download button saves only the output. The work happens entirely inside the browser tab, so the content of the textarea never leaves your machine.

Questions People Ask About Removing Spaces

Why does the tool keep my line breaks?

The expression matches only spaces and tabs, so newlines are preserved on purpose. If the goal is one continuous paragraph, the remove-line-breaks page does that instead.

Does it fully clean text pasted from Word?

It collapses ordinary spaces and tabs, but Word frequently inserts non-breaking spaces that survive the pass. Swap them for regular spaces in your editor, or paste through a plain-text step first.

What happens to my code indentation?

A leading run of four spaces becomes a single space when the line-trim option is off. Enable Trim leading/trailing spaces on each line to strip the indent entirely, or keep the original file for the formatter.

Can I undo the result?

The page keeps no undo history, so copy the original text into a scratch file before converting. The download button saves the output only.

Are tabs inside my text changed?

Yes. Any run that contains a tab is collapsed to a single space, so a tab separating two words becomes a space between them.

What does the line-trim option do that the normal trim does not?

The normal trim touches only the outer edges of the whole document. The line-trim option applies the same removal to every line individually, so each line arrives without leading or trailing space.