Free Remove Empty Lines Tool
Paste text or a list to delete every blank or whitespace-only line. Optional settings let you trim each remaining line or collapse runs of blanks down to a single empty line.
Removed 5 lines.
Quick answer
To remove empty lines, paste your text and the tool splits it on newlines, then drops any line that is empty or contains only spaces or tabs. Turn on "trim each kept line" to clean leading and trailing whitespace, or "collapse blanks" to leave a single blank line between blocks instead of deleting all of them.
Formula & method
Blank-line rule
keep line only if line.trim() !== "" (a line is blank when it is empty or contains only spaces or tabs)
- line — a single line of the input, split on the newline character
Lines removed
removed = total_lines - kept_lines
- total_lines — number of lines after splitting the input on newlines
- kept_lines — number of lines remaining in the output
The text is split into lines on each newline character. Every line is tested with a whitespace check: if what remains after stripping spaces and tabs is empty, the line is considered blank. In the default mode, all blank lines are dropped and only non-empty lines are kept. With "collapse blanks" enabled, consecutive blank lines are reduced to a single empty line so paragraph spacing is preserved while excess gaps disappear. With "trim each kept line" enabled, leading and trailing whitespace is removed from every retained line. The remaining lines are rejoined with newlines, and the tool reports how many lines were removed. Everything runs locally in your browser, so your text is never uploaded.
Examples
- Input
- apple banana cherry
- Result
- apple banana cherry
- Why
- Every empty line between the words is deleted, leaving three lines. The tool reports 3 lines removed.
- Input
- hello world (trim each kept line on)
- Result
- hello world
- Why
- The middle line holds only spaces, so it is treated as blank and removed; trimming then strips the padding around "hello". One line removed.
- Input
- a b c (collapse blanks on)
- Result
- a b c
- Why
- Runs of blank lines are reduced to a single empty line, preserving spacing between blocks. Two extra blank lines are removed.
When to use this tool
- Cleaning a pasted list of emails, names, or URLs that has stray blank rows.
- Tidying text copied from a PDF or web page that arrives with double or triple line breaks.
- Compacting code, config, or log output by removing or collapsing empty lines before sharing.
Common mistakes
- Assuming a line with only spaces or tabs is kept — it counts as blank and is removed unless you copy it as visible characters.
- Expecting indentation to survive when "trim each kept line" is on; that option strips leading whitespace too, so disable it to preserve indents.
- Using the default mode when you actually want paragraph spacing — switch on "collapse blanks" to keep one empty line between blocks instead of deleting them all.
Frequently asked questions
How do I remove empty lines from text?
Paste your text into the box. The tool splits it into lines and removes any line that is empty or contains only spaces or tabs, then shows the cleaned result you can copy.
Does it remove lines that contain only spaces or tabs?
Yes. A line is treated as blank if nothing remains after stripping spaces and tabs, so whitespace-only lines are removed along with truly empty ones.
Can I keep one blank line between paragraphs?
Enable "collapse blanks (keep one)". Instead of deleting every empty line, the tool reduces each run of blank lines to a single empty line, preserving the spacing between blocks.
What does "trim each kept line" do?
It removes leading and trailing spaces and tabs from each line that is kept. Leave it off if you need to preserve indentation.
Will it reorder or sort my lines?
No. The original order of the remaining lines is preserved exactly; only blank lines are removed or collapsed.
Is my text uploaded anywhere?
No. All processing happens in your browser using plain JavaScript, so your text never leaves your device.
How many lines were removed?
The tool shows a live count of how many lines it removed, which is the difference between the original line count and the kept line count.
Sources & references
External references open in a new tab. We are independent and not affiliated with these organizations.
- ✓ Free to use
- ✓ No sign-up required
- ✓ Runs entirely in your browser — nothing is uploaded.
- ✓ Formula and method shown above
Provided “as is” for general information only — results may be inaccurate, so verify before you rely on them. No warranty; use at your own risk.
Built and reviewed by HIFreeTools against the formula shown above and any authoritative references cited on this page. See our methodology and editorial standards.
Related tools
Embed this tool on your site
Free to embed, no sign-up. Paste this code where you want the remove empty lines to appear: