Trim Whitespace
Trim whitespace from text. Strip leading and trailing spaces from each line, collapse runs of spaces to one, normalize line endings, remove blank lines.
Messy in, clean out
Strip leading/trailing whitespace per line, optionally collapse internal runs, normalize newlines, drop blanks.
hello, world! the quick brown fox jumps over the lazy dog
hello, world! the quick brown fox jumps over the lazy dog
What you'll use this for
Pasted text, scraped data, log files — anywhere stray spaces, tabs, and odd line endings sneak in.
Copy-paste cleanup
Strip ragged spaces and odd line endings introduced when copying from PDFs or web pages.
Log filter
Drop blank lines and normalize CRLF to LF before grepping or diffing log output.
CSV cleanup
Trim each cell value column-by-column to fix exports with padding around fields.
Code formatting
Convert tabs to spaces, drop trailing whitespace, and tidy line endings before committing.
How to trim whitespace
Paste your text
Drop the messy text into the left editor. Any size, any encoding.
Pick what to trim
Per-line trim is on by default. Add collapse, normalize, blank-line removal, or tab conversion as needed.
Click Trim
Or leave auto-trim on for live updates. Runs locally — no upload.
Copy or download
Copy to clipboard or save as trimmed.txt. The Saved stat shows the percentage shrunk.
Frequently asked questions
This tool handles visible whitespace: spaces, tabs, line endings. Text cleaner handles invisible junk: zero-width characters, BOMs, smart quotes, control characters. Run text-cleaner first if you suspect invisible characters, then trim.
No. The Trim each line toggle strips leading whitespace, which wipes indentation. Disable that toggle and instead enable Tabs → spaces and Normalize newlines if you only need to tidy code without flattening it.
Yes. No signup, no limits, no ads. Runs entirely in your browser.
Both Windows-style CRLF and old-Mac-style CR are converted to Unix LF. Useful before diffing files or piping through tools that expect a single line-ending convention.
Yes. Newlines themselves are preserved — only the spaces around them are trimmed. If you also enable Remove blank lines, fully-empty lines are dropped.
About trimming whitespace
Whitespace — spaces, tabs, line endings — accumulates as text passes between systems. Pasting from PDFs introduces stray spaces. Copying from Windows produces CRLF. Database exports add padding around field values. This tool fixes all of that.
What each option does
- Trim each line — removes leading and trailing spaces, tabs, and any other whitespace from every line.
- Collapse internal spaces — turns runs of spaces or tabs into a single space.
- Remove blank lines — drops lines that contain nothing (or only whitespace) after trim.
- Normalize newlines — converts
CRLFandCRtoLF, matching the Unix convention. - Tabs → spaces — replaces each tab character with two spaces.
Tips
- Run text-cleaner first if you're dealing with copy-pasted Word or PDF text — it strips invisible junk.
- Disable Trim each line if you need to preserve indentation in code.