# Remove Empty Lines

URL: https://hifreetools.com/text/remove-empty-lines

> 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.

## 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

- Blank-line rule: keep line only if line.trim() !== "" (a line is blank when it is empty or contains only spaces or tabs)
- Lines removed: removed = total_lines - kept_lines

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

- Remove all blank lines: apple banana cherry → apple banana cherry
- Whitespace-only line with trim: hello world (trim each kept line on) → hello world
- Collapse blanks to one: a b c (collapse blanks on) → a b c

## FAQ

**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

- [MDN: String.prototype.trim()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
- [MDN: String.prototype.split()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
- [Wikipedia: Newline](https://en.wikipedia.org/wiki/Newline)

Runs in the browser; nothing is uploaded. Cite as: HIFreeTools, "Remove Empty Lines", https://hifreetools.com/text/remove-empty-lines
