Trim whitespace
Trim leading, trailing, or both sides of whitespace on every line or around the entire text.
How it works & useful details
How to use this tool
Choose each line to remove indentation or trailing spaces line by line. Choose whole text to trim only the outer boundaries, preserving interior whitespace and line endings.
How the result is calculated
Uses JavaScript trim rules, including tabs, line breaks, nonbreaking spaces, and U+FEFF. It preserves zero-width space U+200B. Each-line mode preserves the number of lines and normalizes CRLF and CR to LF; it does not remove blank lines.
Up to 500,000 UTF-16 code units per input. Text stays on your device.
About this tool
Trim whitespace removes leading and trailing spaces, tabs, and other whitespace from every line or from the whole text. It is the routine cleanup before comparing or importing a list.
Both modes are exact and local: per-line trimming keeps the text structure, while trimming the whole document only affects its outer edges. The result is copyable and downloadable.
How to use it
- Paste the text with unwanted whitespace.
- Choose per-line or whole-document trimming and which sides to trim.
- Review the result and the reported changes.
- Copy or download the cleaned text.
Worked example
In "each line" mode with both sides selected,
indented line
Tabbed becomes
indented line
TabbedSpaces and tabs at the start and end of every line are removed, while spaces between words stay. In "whole text" mode, only the whitespace before the first character and after the last is removed, and the indentation of the lines in between is kept.
Why stray whitespace matters
Trailing spaces are invisible but significant. They make "Berlin" and "Berlin " different values in a lookup, a deduplication, or a database unique index. They also break exact password or code comparisons and create noise in version control diffs. Trimming is a safe first step before comparing or importing any pasted list.
Trimming follows JavaScript's whitespace definition, which includes non-breaking spaces and the byte-order mark. The zero-width space (U+200B) is not whitespace in that definition, so use remove invisible characters for it.
Frequently asked questions
Does trimming remove spaces inside a line?
No. Only the edges are affected; interior spacing stays intact.
How are tabs and nonbreaking spaces treated?
Standard whitespace characters are trimmed; unusual invisible characters should be handled with the Remove invisible characters tool.
What is the limit?
Up to 500,000 characters of text.
Can I trim only one side?
Yes. Choose leading only (for example, to remove indentation) or trailing only (for example, to clean line ends before committing code).
