Trim Leading Whitespace
Remove leading whitespace from every line — spaces, tabs, or both. Browser-only.
0 characters
0 characters
About Trim Leading Whitespace
This tool strips whitespace from the start of each line in your input. Other whitespace inside the line, and trailing whitespace, are left alone. It's the per-line equivalent of Python's str.lstrip() or JavaScript's String.prototype.trimStart().
When to use it
- Removing the indentation from a copy-pasted code block
- Cleaning up output where every line starts with extra spaces
- Normalizing a list before further processing
- Stripping bullet-list indentation before reformatting
How it works
The input is split into lines (LF and CRLF both handled). Each line's leading whitespace is removed via a regex that matches /^[ \t]+/. The lines are then joined back with LF.
Examples
Hello World indented
Hello World indented
Frequently asked questions
- Are tabs removed?
- Yes. The regex matches both spaces and tab characters at the start of each line.
- Does it affect trailing whitespace?
- No — only leading. Use trim-trailing for the end of lines, or trim-all for both.