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
- Copying from web pages. Table cells and list items carry the indentation of the HTML source.
- Spreadsheets. Cells that were manually typed often end with a space someone pressed before Enter.
- PDFs. Text extraction inserts spacing to reproduce visual layout.
- Wrapped email. Line breaks added by a mail client leave trailing spaces behind.
- Code editors. Auto-indent leaves whitespace on blank lines, which most linters complain about.
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.
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
- Paste your text into the box.
- Leave "Trim start" and "Trim end" ticked — that is standard trimming.
- Tick "Collapse double spaces" only if your text is prose, not aligned columns.
- Press "Trim" and copy the cleaned text.
Related tools
Frequently asked questions
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.
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.
No. Trimming leaves line structure alone. Use the remove empty lines tool, or the button on this page, if you want them gone.
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.
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.