Whitespace Remover

How to Remove Blank Lines from Text

Copied text from a PDF or email and now you have empty lines everywhere. Here is how to remove them — instantly online, or in Word, VS Code, Excel, and Python.

Why blank lines appear in pasted text

PDFs encode paragraph spacing as extra line breaks. HTML pages use <p> and <div> tags that become blank lines when pasted as plain text. Email clients add blank lines between quoted sections. When you paste this text into a document or text field, the empty lines come with it.

Method 1: Online (fastest, any device)

Go to quicktoolshub.org/whitespace-remover. Paste your text, enable Remove blank lines, click Remove Whitespace, and copy. Done in seconds.

Method 2: Microsoft Word

  1. Press Ctrl+H to open Find & Replace
  2. In Find what: type ^p^p
  3. In Replace with: type ^p
  4. Click Replace All and repeat until no more replacements are found

Method 3: VS Code

  1. Open Find & Replace: Ctrl+H
  2. Enable regex mode (the .* icon)
  3. In Find: ^\n or ^\s*\n
  4. Leave Replace empty and click Replace All

Method 4: Python

# Remove completely empty lines
cleaned = '\n'.join(line for line in text.splitlines() if line.strip())

# Or with regex (also handles lines with only spaces/tabs)
import re
cleaned = re.sub(r'\n\s*\n', '\n', text)

Remove blank lines now

Paste text, enable Remove blank lines, copy clean output. Free, no sign-up.

Use Whitespace Remover →

Frequently asked questions

How do I remove blank lines from text online?

Use the free Whitespace Remover at quicktoolshub.org/whitespace-remover. Paste your text, enable 'Remove blank lines', click Remove Whitespace, and copy the result. It deletes all empty lines — including lines that contain only spaces — instantly in your browser.

How do I remove blank lines in Word?

Open Find and Replace (Ctrl+H). Click More > Use wildcards (or check 'Use wildcards' if available). In the Find field enter ^13^13 (or ^p^p for paragraph marks). In Replace enter ^13 (or ^p). Click Replace All. This collapses double paragraph breaks to single ones. Repeat to remove all consecutive blank lines.

How do I remove blank lines in Notepad++ or VS Code?

In Notepad++: open Find and Replace (Ctrl+H), enable Regular expressions, enter ^\r?\n in Find, leave Replace empty, click Replace All. In VS Code: open Find and Replace (Ctrl+H), enable regex mode (.*), search for ^\n and replace with nothing, or use the command palette and search for 'Remove blank lines'.

How do I remove blank lines in Excel?

To remove blank rows in Excel: select your data range, press Ctrl+G (Go To), click Special, select Blanks, click OK. This selects all empty cells. Then right-click and choose Delete > Entire Row. For blank lines within a cell, use Find and Replace with Ctrl+J in the Find field (which represents a line break) and nothing in Replace.

How do I remove blank lines in Python?

Use a list comprehension to filter out empty lines: cleaned = '\n'.join(line for line in text.splitlines() if line.strip()). This removes lines that are completely empty or contain only whitespace. For files, read line by line and write only non-empty lines to the output file.

What causes blank lines to appear in copied text?

Blank lines most commonly appear when copying from PDFs (which encode paragraph spacing as line breaks), from HTML pages (which use div and p tags that become blank lines when pasted as plain text), from email clients (which add line spacing between quoted sections), and from code or log files that use blank lines to separate blocks.