Guide

Line Counter: How to Count Lines in Text

Learn what counts as a line, the difference between total lines and non-empty lines, and when line count matters.

3 min read Updated Jul 2026

Quick Answer

A line counter counts the number of lines in a block of text by splitting on newline characters. A single line of text counts as 1 line; "Hello\nWorld" counts as 2 lines. The total line count includes blank lines. The non-empty line count excludes lines that contain only whitespace. Use it to count lines of code, get a quick row count, or check the csv row count of a pasted table.

Try The Line Counter →

How Lines Are Counted

Text is split on newline characters (line feed \n). Each segment between newlines is one line, including any trailing segment after the last newline. For example:

  • "Hello": 1 line
  • "Hello\nWorld": 2 lines
  • "Hello\n\nWorld": 3 lines (one blank line between)
  • "Hello\nWorld\n": 2 lines (a trailing newline can add or remove a line, and here it does not add an extra line)

If those breaks are the problem rather than the thing you want counted, here is how to remove line breaks and join the text into one paragraph.

Total Lines vs Non-Empty Lines

Total lines counts every line, including blank lines and lines that contain only spaces or tabs.

Non-empty lines counts only lines that contain at least one non-whitespace character, meaning actual content.

For a typical document with blank lines between paragraphs, total lines will be higher than non-empty lines. Use non-empty lines when you want to count only meaningful content rows, for example when checking a CSV file that should have a specific number of data rows.

How to estimate rows in a CSV paste: for a CSV row count, paste the data and read the non-empty line count, then subtract 1 for the header. That gives the number of data rows without opening a spreadsheet.

Lines vs Paragraphs

Lines and paragraphs measure different things. A line ends at every newline character. A paragraph is a block of text separated by one or more blank lines (a double newline). A single paragraph can contain many lines if it is long and has manual line breaks inside it. Neither count measures length in words; for that, see how word count works.

When to Use a Line Counter

  • Counting lines of code in a file or snippet
  • Verifying the number of records in CSV or log data
  • Checking the number of lines in poetry or structured lists
  • Comparing line counts before and after editing a document
  • Validating that a text field contains a required minimum number of lines

Common Mistakes

You May Also Need

You may also need

Next steps

Alternatives

Continue Learning