Blank line collapser — squeeze runs of empty lines down to one

Paste text or code with too many empty lines and get it back with every run of blank lines cut to the number you choose, plus a count of how many lines were removed.

Live demo · real result from this tool

Collapsed

Dear team, The release is ready. Thanks, Asha
Blank lines removed6

Processed on your device — nothing is uploaded.

How to use the blank line collapser

  1. Paste your text into the Text box. The sample is a short email with uneven gaps.
  2. Set Blank lines to keep in a row, from 0 to 5 (default 1).
  3. Decide on Treat whitespace-only lines as blank and Remove blank lines at the start and end (both on by default).
  4. Copy the Collapsed text; Blank lines removed shows how many went.

What it does and when to use it

Extra empty lines creep in when text is copied from PDFs, web pages and chat apps, or when templates leave gaps. They make reviews noisy and documents look broken. This tool keeps your paragraph and section breaks but removes the excess, without touching anything on the non-blank lines.

Code style guides often limit blank lines; Python’s PEP 8, for example, puts two around top-level functions and classes. Set the limit to match. For a fuller tidy-up, the whitespace normalizer fixes trailing spaces and line endings, the line counter shows how many blank lines a file has, and the Python code cleaner limits blank lines while re-indenting.

How it works

The text is split into lines and read from top to bottom in your browser. A counter tracks how many blank lines have appeared in a row:

  • While the count is at or below your limit, blank lines are kept.
  • Once it goes over, each further blank line is dropped and counted as removed.
  • Any non-blank line resets the counter and is copied unchanged.

When trimming is on, blank lines left at the very start and very end are also removed and counted. Lines that hold only spaces are written as truly empty lines when they are treated as blank.

Worked examples

These are the tool’s own outputs.

The sample email, default settings. Three empty lines after “Dear team,”, a gap made of one space line plus one empty line, and three empty lines at the end become:

Dear team,

The release is ready.

Thanks,
Asha

with Blank lines removed: 6.

Limit 0. The same email loses all 8 blank lines and becomes four lines in a row.

Python spacing, limit 2. import os followed by four empty lines and then def main(): keeps exactly two empty lines between them, matching PEP 8. The trailing newline is trimmed, so 3 lines are removed in total.

Space-only lines kept. Between a and b, two lines of three spaces each, with Treat whitespace-only lines as blank unticked: nothing is removed, because those lines are not empty.

Limits and tips

  • No awareness of code. Blank lines inside multi-line strings or Markdown code blocks are collapsed too; check those parts.
  • Line endings become LF when lines are joined again.
  • Leading gaps are kept when trimming is off, but are still cut to your limit.

Frequently asked questions

What counts as a blank line?
With Treat whitespace-only lines as blank ticked (the default), any line containing only spaces or tabs counts, and the lines that are kept are emptied of those spaces. Unticked, only truly empty lines count, so a line with a single space survives.
How do I remove every blank line?
Set Blank lines to keep in a row to 0. Paragraphs then run together with no gaps, which suits lists, log files and data you want one item per line.
Why is the last newline gone?
With Remove blank lines at the start and end ticked, the empty line after a final line break also counts as a blank line at the end and is removed. Add a newline back if your file needs one, or use the whitespace normalizer, which ends text with exactly one.
Will it join my paragraphs together?
Only if you set the limit to 0. With the default of 1, one empty line stays between paragraphs and only the extra ones go.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close