Trim Lines
Remove leading and/or trailing spaces from every line in your text. Clean up messy code, align columns, and prepare data for further processing. Choose what to trim — start, end, or both — and the result updates instantly. No signup, no uploads, completely private.
Why use this Trim Lines tool?
Extra spaces at the start or end of lines can break formatting, mess up data alignment, and cause issues in scripts or config files. This tool cleans them instantly, giving you neat, predictable output. It's faster than manual editing and safer than a script you'd have to write.
- Flexible trimming – choose to trim only the start, only the end, or both ends of each line.
- Skip empty lines – optionally remove lines that become empty after trimming (or keep them if they had content).
- Instant preview – see the cleaned text as you type (with a short debounce) or when you click Trim.
- 100% private – all processing is done locally; your text never leaves your device.
How to trim lines (step‑by‑step)
1. Paste your text
Drop the lines with unwanted spaces into the left box.
2. Choose trim mode
Select whether to clean leading spaces, trailing spaces, or both.
3. Set empty line handling
Toggle "Skip completely empty lines" to remove lines that have no content after trimming.
4. Copy or download
The cleaned text appears on the right. Use the buttons to copy it to your clipboard or save as a .txt file.
Example: cleaning indented code
| Input lines | Output (trim both, skip empty) |
|---|---|
| if (x) { console.log("hello"); } | if (x) { console.log("hello"); } |
Common use cases
- Code cleanup: Remove leading indentation from copied code blocks to re‑indent them later.
- Data preparation: Clean CSV or log data where trailing spaces might cause parsing errors.
- Configuration files: Ensure no hidden spaces sneak into config values.
- Whitespace normalization: Before sorting, removing duplicates, or joining lines, make whitespace consistent.
Pro tips
- Use "Trim leading only" to remove indentation while keeping space at the end of lines (e.g., for trailing comments).
- Combine with our Whitespace Cleaner to also collapse multiple spaces into one.
- If you need to trim specific characters (not just spaces), try the Text Replacer to strip them first.