Trim Whitespace
Trim leading and trailing whitespace.
Loading tool…
About this tool
Paste text and press Run to remove spaces and tabs from the beginning and end of each line. The text between words is not touched.
How to use
1
Step 1
Paste your lines into Input.
2
Step 2
Press Run.
3
Step 3
Copy the trimmed lines.
How it works
Each line is trimmed separately, not just the whole text. Blank lines remain as empty lines. Spaces inside a line are not collapsed, so combine this with Remove Extra Spaces for a full clean-up.
Worked example
Indented lines
- Input
- hello world
- Output
- hello world
- Walkthrough
- Spaces and the tab at the ends of both lines are removed. The final line break is preserved.
Limitations
- Does not shorten spaces between words.
- Does not delete empty lines.
Questions
How do I remove leading and trailing spaces?
Paste the text and press Run. Each line is trimmed.
Does it trim every line or only the whole text?
Every line.
Will it fix double spaces between words?
No. Use Remove Extra Spaces.
Features
- Per-line trim
- Inner spacing untouched
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
HTML in 100 Seconds
Fireship
Quick HTML mental model next to text transform tools.
Watch on YouTubeLearn JSON - Full Crash Course
freeCodeCamp.org
Structured text formats often sit next to plain-text tools.
Watch on YouTube
- String
MDN
JS string methods that mirror case, trim, and split tools.
- UTF-8 and BOM
W3C
Encoding gotchas when cleaning pasted text.