Line Counter

Count lines, blank lines, words and characters in text.

  • Runs locally in your browser
  • No upload required

Try it

CRLF and lone CR line endings are counted the same as LF.

Lines
4
Non-empty lines
3
Blank lines
1
Words
3
Characters
14
Longest line
5
Lines: 4
Non-empty: 3
Blank: 1
Words: 3
Characters: 14
Longest line: 5

Supported formats

Input
text
Output
number, text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Counted 4 line(s), 3 word(s) and 14 character(s).

How it works

  • Normalised CRLF and lone CR line endings to LF.
  • Split the text into logical lines; one trailing newline is not an extra line.
  • Counted non-empty and blank lines.
  • Counted words as whitespace-separated runs and characters by Unicode code point.
  • Measured the longest line by code point.
  • Characters are counted by Unicode code point, not UTF-16 units.
  • The same logical text counts identically whether it uses LF or CRLF.

Methodology

  1. Normalise every CRLF and lone CR to LF.
  2. Split into logical lines, treating one trailing newline as the line terminator rather than a new line.
  3. Count non-empty lines as those whose trimmed length is greater than zero.
  4. Count words over the trimmed text and characters by Unicode code point.
  5. Report the longest line by code point.

Usage

  1. Paste or type the text to analyse.
  2. Run the tool.
  3. Read the counts; the longest line shows the widest line by code point.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Mixed lines

jsonSelect to copy
{
  "text": "one\ntwo\n\nthree"
}

CRLF document

jsonSelect to copy
{
  "text": "alpha\r\nbeta\r\ngamma"
}

Empty input

jsonSelect to copy
{
  "text": ""
}

Limitations

Counting lines correctly

Most disagreements about a line count come from line endings and trailing newlines. This tool normalises CRLF and CR to LF and treats a single trailing newline as a terminator, so the count matches what an editor shows.

Frequently asked questions

How are CRLF line endings handled?
They are normalised to LF before counting, so a file saved with Windows line endings counts the same as one with Unix endings.
Why does the character count differ from the byte count?
Characters are counted by Unicode code point. A non-ASCII character such as é is one character but two UTF-8 bytes.

Sources

  1. ECMA-262: ECMAScript Language Specification — Ecma International
  2. MDN Web Docs — String.prototype.split() — Mozilla