String Trim Lines

Free trim-lines tool: trim leading and trailing whitespace from every line of a block of text, collapse extra spaces, and remove blank lines. Runs entirely in your browser.

Enter text above.

How string trim lines works

This tool processes a block of text one line at a time. It trims the leading and trailing whitespace from every line, so indentation and stray spaces at the end of each line are removed without flattening the whole block into a single line.

Two options control the behaviour. "Drop blank lines" removes any line that becomes empty after trimming, which is ideal for tidying up copied code, CSV output, or pasted text padded with blank rows. "Collapse internal spaces" squeezes runs of spaces and tabs inside each line down to a single space, normalising messy spacing without destroying the line structure.

Everything runs locally in your browser. Nothing is uploaded, so it is safe to paste sensitive text. The result shows the original and final line counts plus the number of blank lines dropped, and you can copy the cleaned block from the result panel.

Frequently asked questions

How is this different from the Trim Whitespace tool?
Trim Whitespace works on the whole string, collapsing all whitespace (including newlines) into single spaces. Trim Lines is line-aware: it keeps your line structure intact and only cleans the leading, trailing, and internal spacing of each individual line, optionally removing blank lines.
Does it remove blank lines?
Yes. "Drop blank lines" is on by default and deletes any line that is empty after trimming. Turn it off to keep blank lines in place but still trim the surrounding whitespace of every other line.
What does "Collapse internal spaces" do?
It replaces runs of spaces and tabs inside each line with a single space, so "a b" becomes "a b". This normalises messy internal spacing without merging lines together.
Is my text stored or sent anywhere?
No. All processing happens in your browser. Your text is never uploaded or stored.