Text Trimmer — Remove Leading & Trailing Whitespace from Lines (Free)
Trim leading or trailing spaces, tabs, and newlines from text or every line. Strip empty lines optionally. Free, browser-based.
About Text Trimmer
A text trimmer removes leading and trailing whitespace — spaces, tabs, and newlines — from a text block as a whole or from every line individually, optionally stripping completely empty lines. The ZTools Text Trimmer offers four common modes (trim start only, trim end only, trim both, trim per-line), preserves intentional internal whitespace, can collapse empty lines into single empty separators, and works on any size paste — fixing the invisible whitespace bugs that break form validation, cause "Apple" and "Apple " to count as different items, and pollute log analysis.
Use cases
- Cleaning copy-pasted user input before submission. Forms reject "user@example.com " (trailing space) as an invalid email. Trim before submitting and save the round-trip.
- Pre-processing a list before deduplication. "Apple\n" and "Apple \n" deduplicate as different items. Trim per-line first, then deduplicate — the right order matters.
- Removing indentation from a code paste. Paste indented code, trim per-line to get unindented output. Useful when copying snippets from articles where leading whitespace breaks Python indentation.
- Cleaning translation files and config exports. Translators sometimes leave trailing spaces around punctuation. A per-line trim normalizes the file before checking it into version control.
How it works
- Paste your text. Any size. Whitespace inside lines is preserved unless you enable inner-collapse mode.
- Pick the trim mode. Trim whole text (only the very start and very end of the paste), trim each line (every line's leading + trailing whitespace), trim start only, trim end only.
- Optional: handle empty lines. Keep empty lines as-is, collapse runs of empty lines to one, or remove all empty lines entirely.
- Copy the output. Side-by-side preview shows before and after. One-click copy or download.
Examples
Input: " hello \n world \n"
Output: "hello\nworld" (per-line trim, empty lines removed)
Input: "Apple \nBanana\n Cherry"
Output: "Apple\nBanana\nCherry" (per-line trim)
Input: "\n\n\nReal content\n\n"
Output: "Real content" (whole-text trim)
Frequently asked questions
What's the difference between "trim text" and "trim lines"?
"Trim text" removes whitespace only at the very start and end of the entire paste — useful when removing leading/trailing newlines from a copied block. "Trim lines" trims every individual line — useful for cleaning user-input lists.
Does trimming remove tabs and newlines too?
Yes — by default, trim removes any Unicode whitespace: space, tab, newline (LF), carriage return (CR), zero-width space, non-breaking space. You can configure which characters count as "whitespace".
Will it touch whitespace inside lines?
No — trim only removes whitespace at the start or end. Internal multi-space ("hello world") stays as-is. To collapse internal whitespace, use the Multiple Whitespace Remover tool.
Why are some "spaces" not removed?
They might be non-breaking spaces (U+00A0) or zero-width characters (U+200B). The default trim handles Unicode whitespace, but check the option panel if anything looks left over.
Should I trim before or after deduplication?
Always before. Trim normalizes the comparison so "Apple " and "Apple" are seen as identical when deduplicating.
Pro tips
- Always trim user input before validating, comparing, or storing — invisible whitespace bugs are the #1 form-validation issue.
- When importing CSVs, trim each cell before parsing to handle the "Excel exported with trailing spaces" problem.
- For source code, trim trailing whitespace per line (most editors do this on save) but never leading — that breaks indentation.
- Combine with the "remove empty lines" option for clean list outputs ready to feed into other tools.
Reviewed by Ahsan Mahmood · Last updated 2026-05-05 · Part of ZTools.
For the full,
formatted version of this page, please enable JavaScript and reload
https://ztools.zaions.com/remove-whitespace.