How to Remove Empty Lines from Text

How to Remove Empty Lines from Text

How to remove empty lines from text: delete blank and whitespace-only lines in seconds, in a browser tool, Word, Google Docs, Excel, and code editors.

How to Remove Empty Lines from Text

If your text is full of gaps, blank lines between every item in a list for example, here is the quick fix. Paste it into a browser text cleaner, switch on remove blank and whitespace-only lines, and copy the cleaned result back. It usually takes less than a minute, and you do not need to install anything, sign up, or upload a file.

Below, I will cover the same cleanup in a browser tool, in Word, in Google Docs, in Excel and Google Sheets, and in code editors such as Notepad++ and VS Code. You will also see when to delete every blank line, when to squash several blank lines into one, and when to leave them right where they are.

Key takeaways

  • Delete all empty lines when you are cleaning a list, a log, or pasted data for reuse.
  • Collapse several blank lines into one when you want readable paragraphs, not a solid wall of text.
  • Treat whitespace-only lines as empty too, because a line holding only spaces or tabs looks blank but is not.
  • Keep blank lines in Markdown, Python, and poetry, where they carry meaning and structure.
  • Check the first and last lines after cleaning, because a stray blank line at the start or end is easy to miss.

How to remove empty lines from text in 30 seconds

Removing empty lines from text is a simple four-step job. The cleaner does the deleting for you; your job is to choose the right mode before you click.

  1. Paste your text. Copy the messy text into a browser text cleaner. Most cleaners process your text on your own device, so nothing is sent to a server.
  2. Choose a mode. Pick “remove all empty lines” for lists and data, or “collapse multiple blank lines into one” for prose that still needs paragraph breaks.
  3. Turn on whitespace-only lines. Make sure lines containing only spaces or tabs are also removed. Without this option, a line that looks blank will survive the clean.
  4. Copy the result. Scan the start and end of the output, then copy it back into your document, spreadsheet, email, or code file.

For ordinary lists, titles, and copied web text, a browser cleaner is the fastest route. For sensitive data, such as customer records, clean the text inside your own document or editor instead of pasting it into any website.

What counts as an empty line?

Not every line that looks blank is really blank, and that difference decides whether a cleaner actually gets rid of it.

A truly empty line contains no characters at all, just a line break. A whitespace-only line contains spaces or tabs before the line break, so it looks blank on screen but is not empty to a simple filter. A line with trailing spaces is not empty either, but it often arrives with pasted text and is worth trimming at the same time.

Line endings add a second complication. Windows uses two characters for a line break, carriage return plus line feed, while macOS and Linux use a single line feed. When text moves between systems, a leftover carriage return can create a phantom blank line that was never in the original. A good cleaner normalises line endings first, then filters the lines, so those ghost lines disappear as well.

Remove-all, collapse, or keep: choosing the right mode

Use this table to pick the mode that matches what you are cleaning, before you delete anything.

ModeWhat it doesBest forWatch out for
Remove all empty linesDeletes every blank line, joining the remaining lines togetherLists, keyword sets, logs, CSV data, code importsRemoves paragraph breaks in prose, so do not use it on articles
Collapse to one blank lineTurns two or more blank lines in a row into a single blank lineArticles, emails, notes, pasted web textStill leaves one blank line between every paragraph, which is usually the point
Remove whitespace-only linesTreats lines holding only spaces or tabs as emptyText copied from PDFs, web pages, and terminalsTurn this on, or invisible blank lines will survive
Trim lines, keep blanksRemoves leading and trailing spaces but leaves blank lines alonePoetry, Markdown, and drafts where spacing mattersDoes not shorten the document at all
Keep blank lines as separatorsLeaves the text untouchedMarkdown, Python, scripts, and verseOnly choose this deliberately, not by forgetting to clean

Before and after: a worked example

Here is a short messy list, and what it looks like after removing all empty lines, including a whitespace-only line.

Before cleaningAfter removing empty lines
AppleApple
(blank line)Banana
BananaCherry
(line with only spaces)Date
Cherry
(blank line)
Date

If the whitespace-only line is still there after cleaning, the cleaner was set to remove only truly empty lines. Turn on the whitespace-only option and run it again. If several blank lines collapse to one instead of disappearing, you chose the collapse mode rather than the remove-all mode.

How to remove empty lines from text in Word

In Microsoft Word, the reliable method is Find and Replace with wildcards. Press Ctrl + H to open Find and Replace, then search for the pattern that matches a paragraph mark followed by another paragraph mark, and replace it with a single paragraph mark. Repeat the replacement until Word reports no more matches, because three blank lines in a row need more than one pass to collapse fully.

To delete every blank line rather than collapse them, replace the double paragraph marks with a single one and repeat until none remain, then check the start and end of the document for a leftover blank paragraph. Word also lets you show paragraph marks, which makes blank and whitespace-only lines visible before you start. Turn that view on first if you are not sure where the extra lines are.

How to remove empty lines from text in Google Docs

Google Docs does not have a one-click remove-empty-lines button. The practical options are to use Find and Replace with a regular expression, or to paste the text into a browser cleaner, clean it there, and paste it back.

For a short document, the browser-cleaner round trip is usually faster and less error-prone than building a regex. For a long document that lives in Docs, use Find and Replace, work on a copy first, and check headings and paragraph breaks afterwards, because a global replace can also join paragraphs you wanted to keep apart.

How to remove empty lines in Excel and Google Sheets

In a spreadsheet, an “empty line” is usually an empty row, and the fix is different from cleaning plain text. Select the data, use a filter to show blank rows, and delete those rows, or sort the column so blank rows gather at the bottom and delete them there.

Be careful when a row looks blank but holds a space, a formula returning an empty string, or a value in a far-right column. Filtering for blanks will not always catch those, so scan the row before deleting it. Never delete rows from only one column of a multi-column table, because that will scramble your records. Delete the whole row, across all columns, together.

How to remove empty lines with Notepad++ and VS Code

Code editors handle this job with regular expressions, and the pattern is short once you know it. In Notepad++ or VS Code, open Find and Replace, turn on regular expressions, and replace lines that contain only whitespace with nothing. A common pattern matches the start of a line, any spaces or tabs, and the line break that follows.

Editors differ in the exact pattern they need, so check the editor’s own searching documentation before you run a replace across a whole file, and test it on a copy first. The official Notepad++ searching guide is a good primary reference for its replace syntax. For code, consider collapsing blank lines to one instead of deleting them all, because a single blank line between blocks is a normal readability convention in most languages.

Cleaning up the rest of the mess at the same time

Empty lines rarely arrive alone. Pasted text often brings extra spaces, broken lines, and duplicates with it, and cleaning those together gives a much tidier result.

  • Extra spaces: collapse repeated spaces inside lines first, as covered in our guide on how to remove extra spaces in text, so lines do not end up ragged after blank lines are removed.
  • Broken lines: if your paste arrives split across lines, fix the breaks first with our guide on how to remove line breaks, then remove the empty lines that remain.
  • Duplicates: after cleaning, duplicates are easier to spot, especially in a list. See our guide on how to remove duplicate lines for that step.
  • Sorting: once the list is clean, it is ready to sort. Our guide on how to sort lines alphabetically online covers case, numbers, and natural sort order.

When you should NOT remove empty lines

Deleting every blank line is the wrong move in a few common formats. In Markdown, a blank line separates paragraphs, list items, and blocks, so removing it can merge text that was meant to stay apart. In Python, blank lines separate functions and logical blocks, and while the code will still run without them, it becomes much harder to read. In poetry, screenplays, and song lyrics, blank lines mark stanzas, scenes, and verses.

The rule is simple: if blank lines carry meaning in the format, collapse them to one instead of deleting them, or leave them alone. If blank lines are just noise from copying and pasting, delete them without hesitation.

Questions people ask about removing empty lines

How do I remove empty lines from text online for free?

Paste your text into a free browser text cleaner, turn on the option to remove blank and whitespace-only lines, and copy the cleaned result. Free cleaners need no sign-up, and most run entirely in your browser, so your text is not uploaded to a server.

Why are there still blank lines after I clean my text?

Usually because the remaining lines contain only spaces or tabs, so they are not truly empty. Turn on the whitespace-only option and clean again. If the text came from Windows, mismatched line endings can also leave ghost blank lines, which a cleaner that normalises line endings will remove.

What is the difference between an empty line and a blank line?

In everyday use the terms mean the same thing: a line with no visible content. Technically, an empty line has no characters at all, while a blank line can also hold invisible spaces or tabs. For cleaning purposes, treat both as empty and remove both.

Can removing empty lines break my document?

Yes, in formats where blank lines carry meaning, such as Markdown, Python, and poetry. In those cases, collapse multiple blank lines into one instead of deleting them all. For lists, logs, and pasted data, removing every blank line is safe.

Frequently asked questions

How do I remove empty lines in Word?

Use Find and Replace to replace double paragraph marks with a single paragraph mark, and repeat until no matches remain. Show paragraph marks first so you can see exactly where the blank lines are.

How do I remove empty lines in Google Docs?

Google Docs has no dedicated button for this. Use Find and Replace with a regular expression, or paste the text into a browser cleaner, clean it there, and paste it back into Docs.

How do I remove blank rows in Excel?

Filter the data to show blank rows and delete those whole rows, or sort so blank rows gather at the bottom and delete them there. Always delete the full row, not just one column, so your records stay intact.

Is it safe to paste my text into an online empty-line remover?

For ordinary lists, titles, and public text, yes, especially with a cleaner that processes text in your browser. For private or customer data, clean the text inside your own document or editor instead.

Final check before you use your cleaned text

Before you publish, send, or save your cleaned text, scan the first ten lines and the last ten lines. Check that no blank line survived at the start or end, that paragraphs you wanted to keep are still separated, and that no line was accidentally joined to the one above it. That thirty-second check catches almost every cleaning mistake, and it is much cheaper than fixing a published document afterwards.

Once the empty lines are gone, your text is ready for its real job: sorting, deduplicating, pasting into a spreadsheet, or publishing as a clean list. Keep the same quick cleaning habit for every paste, and messy text will stop slowing you down.

For the editor replace syntax, see Notepad++ User Manual: Searching.