Menu

Remove Empty Lines

Paste your text to delete every blank line at once. Lines that contain only spaces or tabs count as empty too, and one option keeps a single blank line between paragraphs instead of removing them all.

0 words 0 characters 0 lines

Continue with this text: Remove extra spacesRemove line breaksRemove duplicates

Your text stays in your browser: nothing is uploaded or stored on a server.

How to remove empty lines

  1. Paste your text into Your text, type it, drag a file onto the box or click Open file to load a plain-text file (.txt, .csv, .md and similar). Click Example to try it with sample text.
  2. Leave Treat lines with only spaces as empty ticked to remove lines that only look empty, or untick it to remove truly empty lines only.
  3. Tick Keep one empty line between paragraphs if you want paragraphs to stay separated rather than packed together.
  4. The Result box updates as you type. Click Copy, Download .txt, or Use as input to keep working on the cleaned text (an Undo button brings the original back).

The text never leaves your browser, so you can clean customer lists, logs or private notes safely.

The two options

The options combine into four results. Here is the tool’s own example, with the spaces on the fifth line shown as :

First line


Second line
   
Third line



Fourth line
Only spaces = empty One line between paragraphs Result
On (default) Off All four text lines directly under each other, nothing between them
Off Off Same, but the line with three spaces stays between Second line and Third line
On On One empty line between each pair of text lines
Off On One empty line between most pairs; the three-space line takes the place of the gap between Second line and Third line

With the default settings, the result is:

First line
Second line
Third line
Fourth line

With both options on, it is:

First line

Second line

Third line

Fourth line

Exactly what counts as an empty line

The tool splits your text into lines at every line break, whether it is a Windows (CRLF), Unix (LF) or old Mac (CR) break, and then looks at each line on its own.

  • Truly empty lines (no characters at all) are always removed.
  • Whitespace-only lines are removed when the first option is on. Whitespace here means spaces, tabs, no-break spaces (often pasted from web pages and Word) and the other Unicode space characters, such as the wide ideographic space used in Japanese and Chinese text.
  • Zero-width characters are not whitespace. A line holding only a zero-width space (U+200B) looks empty but is kept. Our guide to zero-width spaces and other invisible characters explains where they come from.
  • Lines with text are never edited. Indentation, tabs and trailing spaces on those lines stay as they were, so code and indented lists keep their shape.

How “keep one empty line” works

With Keep one empty line between paragraphs on, the tool walks through the lines and keeps an empty line only when the line before it contains text. The effect:

  • Two, three or ten blank lines in a row become exactly one.
  • Blank lines before the first line of text and after the last one are removed completely.
  • When whitespace-only lines count as empty, the line that is kept is truly empty: its spaces and tabs are removed.

For example, this input starts with two blank lines and a line of two spaces, has a tab-only line after Body and ends with blank lines:

Before After (both options on)
⏎⏎··⏎Intro⏎⏎⏎⏎Body⏎→⏎⏎End⏎⏎ Intro⏎⏎Body⏎⏎End

(⏎ is a line break, · a space and → a tab.)

If you untick the first option but keep this one on, a line of spaces counts as text. A blank line that follows it is then kept too, so a⏎···⏎⏎b stays unchanged.

Other changes to know about

  • Line endings become LF. The result always uses a single line feed (\n) between lines, whatever line breaks the input used.
  • A final line break is dropped. If your text ends with a line break, the result ends with the last line of text instead.
  • Long text is fine. The tool sets no size limit, and a list of 100,000 lines is processed in well under a second on a typical computer; the input counter under the box shows how many lines you started with.

When people need it

  • Mailing lists and CRM exports. A column of email addresses copied from a spreadsheet often has gaps where cells were empty. Remove the blank lines, then remove duplicate lines so every address appears once.
  • Text copied from web pages, emails and PDFs. Pasted text often arrives double-spaced, with an empty line after every line. Removing empty lines, or keeping one between paragraphs, restores normal spacing. If lines are also broken in the middle of sentences, see how to remove line breaks from PDF text.
  • Lists for code and data. Before turning a list into an SQL IN list or a CSV row with the comma separator, blank lines must go, or they become empty values.
  • Logs and config files. Drop blank lines to make a log shorter to scan, or collapse them to one in a config file you want to tidy.
  • Counting entries. A list with gaps gives a wrong count; clean it first and the line counter shows the real number of items.

Doing it in a text editor instead

In Notepad++, the Edit > Line Operations menu has Remove Empty Lines and Remove Empty Lines (Containing Blank characters); the second also removes lines that contain only spaces or tabs. It has no command for keeping one blank line between paragraphs.

In VS Code and other editors with regular-expression search, open Find (Ctrl+F, or ⌘F on a Mac), expand it to show Replace, turn on the regular expression option, search for ^\s*\n and replace it with nothing. That removes empty and whitespace-only lines but leaves one at the very end of the file if it has no line break after it. This page does the same without a pattern, and adds the option to keep one line between paragraphs.

Questions

How do I remove blank lines from text?

Paste the text into the box. The result appears straight away with every empty line removed; click Copy or Download .txt to take it with you. Nothing is uploaded, because the tool runs in your browser.

Are lines with only spaces treated as empty?

Yes, by default. The option "Treat lines with only spaces as empty" removes lines that contain nothing but spaces, tabs, no-break spaces or other Unicode space characters. Untick it to remove only lines that have no characters at all.

Can I keep one blank line between paragraphs?

Yes. Tick "Keep one empty line between paragraphs". Every run of blank lines becomes a single empty line, so paragraphs stay separated, and blank lines at the very start and end are removed.

Why does a line still look empty after cleaning?

It contains a character that is invisible but is not a space, usually a zero-width space (U+200B) copied from a web page or chat app. Run the text through remove invisible characters first, then remove the empty lines.

Does the tool change the lines that have text?

No. Lines with text are kept exactly as they are, including any indentation or trailing spaces. To trim those as well, use remove extra spaces. The only other change is that Windows (CRLF) and old Mac (CR) line endings become plain LF line breaks.

How do I remove empty lines in Notepad++?

Open Edit > Line Operations and choose "Remove Empty Lines", or "Remove Empty Lines (Containing Blank characters)" to also remove lines with only spaces or tabs. Notepad++ has no option to keep one blank line between paragraphs.

What is the difference between removing empty lines and removing line breaks?

Removing empty lines deletes the blank lines but keeps every line of text on its own line. Removing line breaks joins the lines together, which is what you need for text copied from a PDF.