Trim spaces

Removes whitespace from the start and end of every line, and extra spaces inside.

Choose which kinds of whitespace to remove and press the button. Every line is treated the same way.

The invisible bug

Trailing spaces cause more quiet damage than almost anything else in text handling, precisely because you cannot see them. A value copied from a web table arrives as "apple ". It looks identical to "apple" on screen. Then a lookup returns nothing, a join drops rows, a deduplication keeps both copies, a comparison says two identical lists differ, and you spend twenty minutes checking your logic when the problem is one space.

Leading spaces do the same on the other side, and they also break code indentation, Markdown lists and YAML files where indentation carries meaning.

The four operations

Trim start and trim end are on by default. Together they are what "trim" means in every programming language: remove whitespace from both ends, leave the middle alone.

Collapse double spaces replaces runs of two or more spaces inside a line with one. This is separate on purpose, because it is not always wanted — aligned columns and ASCII tables depend on those runs, and collapsing them destroys the layout. Turn it on for prose, off for anything aligned.

Convert tabs to spaces turns each tab into a single space. Useful when text pasted from a spreadsheet carries tabs that behave unpredictably depending on where you paste it next. If you are converting tab-separated data into another format, the list converter handles the separator properly rather than flattening it.

Line breaks are never touched here. Empty lines stay empty — removing them is a separate operation and there is a button for it above.

Where the spaces come from

A warning about non-breaking spaces

Text copied from Word, PDFs and web pages often contains non-breaking spaces (U+00A0) rather than ordinary ones. They look identical and most trim functions ignore them, which is why some text refuses to clean up no matter how many times you trim it. If that is happening, run the text through the text cleaner, which normalises exotic whitespace first.

Doing it without this tool

Excel: =TRIM(A1) removes leading and trailing spaces and collapses internal runs — all three at once, whether you wanted that or not. It does not touch non-breaking spaces, hence the common pairing =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))).

Notepad++: Edit → Blank Operations has "Trim Trailing Space", "Trim Leading Space" and both together. This is one of the few places where the desktop editor is genuinely quicker.

VS Code: set "files.trimTrailingWhitespace": true and it happens on every save.

Command line: sed 's/^[ \t]*//; s/[ \t]*$//' file.txt.

Try:
0Words
0Characters
0No spaces
0Sentences
0Paragraphs
0Lines
0Pages
0Reading
0Speaking

Runs entirely in your browser. Your text is never uploaded — open DevTools, Network tab, and you will see zero requests while you use this tool.

How to use it

  1. Paste your text into the box.
  2. Leave "Trim start" and "Trim end" ticked — that is standard trimming.
  3. Tick "Collapse double spaces" only if your text is prose, not aligned columns.
  4. Press "Trim" and copy the cleaned text.

Related tools

Sort by lengthOrders lines by how many characters they contain, shortest or longest first.Text cleanerCollapses double spaces, trims line ends and removes repeated blank lines.Remove punctuationStrips punctuation and symbols, optionally keeping apostrophes and hyphens.Remove duplicatesKeeps the first occurrence of every line and preserves the original order.Group generatorPaste names, choose how many groups, get evenly sized random teams.Instagram caption lengthThe hard limit is 2,200 characters. The one that matters is the 125 you see…Bubble textLetters inside circles, or letters inside squares. Copy and paste.

See all text tools →

Frequently asked questions

What is the difference between trimming and collapsing spaces?

Trimming removes whitespace at the start and end of a line only. Collapsing replaces runs of two or more spaces inside the line with a single space. They are separate options because collapsing destroys aligned columns and ASCII tables.

Why does my text still look wrong after trimming?

It probably contains non-breaking spaces, which come from Word, PDFs and web pages and look identical to ordinary spaces. Run it through the text cleaner, which normalises them first.

Does it remove empty lines?

No. Trimming leaves line structure alone. Use the remove empty lines tool, or the button on this page, if you want them gone.

Are tabs removed?

Only if you tick "Convert tabs to spaces", which turns each tab into a single space. Tabs at the start or end of a line are removed by the trim options like any other whitespace.

Does it work on very large text?

Yes. Everything runs in your browser and the operation is linear, so files of several megabytes are handled without a round trip to a server.