Line Counter

Counts the number of lines in your text, distinct from a raw newline-character count, since a non-empty block of text always has one more line than it has newline characters. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-23

Overview

Introduction

'How many lines is this?' sounds simple, but the answer depends on whether you're counting line breaks or the lines those breaks create, and the two numbers differ by exactly one for non-empty text.

It runs entirely client-side, so nothing you paste is ever uploaded to a server.

What Is Line Counter?

A counter that reports the total number of lines in your text, splitting on any of the common line-ending styles.

It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.

How Line Counter Works

The text is split on a regular expression matching \r\n, \r, or \n, and the resulting number of segments is the line count.

The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.

When To Use Line Counter

Use it when you need the actual line count of a document, script, or list, rather than just its newline-character count.

It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.

Often used alongside Newline Counter and String Length Counter.

Features

Advantages

  • Recognizes all three common line-ending styles consistently.
  • Reports the intuitive 'number of lines' figure rather than a raw character count.
  • Splitting rather than counting characters means a trailing newline correctly contributes a final empty line to the total.

Limitations

  • Doesn't distinguish which line-ending style was used, only the total line count.
  • Treats a trailing blank line (text ending in a newline) as an additional counted line, matching how most editors display line numbers.

Examples

Counting the lines in a short list

Input

line one
line two
line three

Output

3

Three lines separated by two newline characters produce a line count of 3, one more than the newline count.

Best Practices & Notes

Best Practices

  • Use Newline Counter instead if you specifically need the newline-character count rather than the line count.
  • Decide up front whether a trailing newline should count as a line, since a file ending in one reports one more than an editor's last line number.
  • Paste the raw text rather than retyping it, because editors frequently add or strip a trailing newline on the way in.

Developer Notes

The implementation is `input.split(/\r\n|\r|\n/).length`, which matches \r\n as a single unit before falling back to lone \r or \n, so Windows-style line endings aren't double-counted and the result is always newline count + 1 for non-empty input.

Line Counter Use Cases

  • Checking a document's or script's total line count
  • Verifying a list has the expected number of entries
  • Comparing line counts before and after an edit

Common Mistakes

  • Confusing line count with newline count; they differ by one for non-empty text.
  • Expecting empty input to report a line count of 1.

Tips

  • Pair with Newline Counter for a complete picture of a document's line structure.
  • Empty input still reports 1, since splitting an empty string yields a single empty segment rather than none at all.

References

Frequently Asked Questions