📝 Text

Line Counter

Paste or type your text below, total lines, non-empty lines, blank lines and the longest line length update instantly as you type.

0
Total Lines
0
Non-Empty Lines
0
Blank Lines
0
Longest Line

About the Line Counter

Drop in a log file, a code snippet, or a block of CSV data and watch the counts update line by line as you type. A line only counts as blank if it's empty or holds nothing but whitespace, everything else falls into the non-empty total, and the longest-line stat is handy for spotting an unwrapped row.

A trailing newline at the end of your text adds one extra counted line

Total lines is computed with text.split("\n"), which splits on every line-break character and returns one array element per split, not per newline. That distinction matters for text that ends with a newline: the string "a\nb\n" contains exactly two newline characters, but splitting on \n produces three array entries — "a", "b", and a trailing empty string after the final break. That trailing empty entry gets counted as one blank line. This matches how most text editors and version control tools treat a file (a file ending in a newline, which is the POSIX-standard way to end a text file, is still considered to have that final blank "line" by many line-counting utilities), but if you're pasting from a source that always appends a trailing newline and expecting the count to match the number of visible rows, it'll read one line higher than expected.

Windows-style line endings inflate the longest-line count by one character

The splitter only breaks on \n, not \r\n. For text using Unix-style line endings this makes no difference, but for text copied from a Windows source using CRLF line endings, each split-out line keeps a trailing, invisible \r character attached to it. That carriage return still counts toward line.length, so the Longest Line stat on CRLF text will read exactly one character higher per line than what's visually on screen — worth knowing if you're using this to check whether a line fits inside a strict character limit like an 80-column code style rule.

Blank-line detection catches more than plain spaces

A line is marked blank using JavaScript's .trim(), which strips more than the space bar's ASCII space character — per the language spec it also removes tabs, carriage returns, and any Unicode "space separator" character, including the non-breaking space (U+00A0) that word processors and some copy-pasted web content silently insert instead of a regular space. So a line that looks empty but actually contains a lone non-breaking space, a common artifact of pasting from a rendered webpage, is still correctly counted as blank here rather than slipping into the non-empty total.

Longest line is measured in UTF-16 code units, not visible characters

The length comparison uses each line's native JavaScript .length, which counts UTF-16 code units rather than what a person would call a single visible character. Most text is unaffected, but characters outside the Basic Multilingual Plane — many emoji among them — are stored as a surrogate pair and count as 2 toward that total instead of 1. A line containing a handful of emoji will therefore report as longer than its visible character count would suggest, which is worth accounting for if you're using the stat to estimate how a line will actually wrap or fit on screen.

Common uses for a per-line breakdown

Developers reach for a line counter most often when checking a code file against a style guide's line-count or line-length limits, verifying a log file's row count matches what a monitoring system reported, or sanity-checking a CSV export before importing it somewhere that expects an exact number of data rows. The non-empty/blank split is particularly useful for spotting formatting problems in pasted text — a document that should read as continuous paragraphs but shows a high blank-line count usually means every line break in the source got preserved as a hard return instead of being treated as reflowable text, which is a common issue when copying from a PDF or a rigidly formatted email.

Frequently Asked Questions

Why does the line count show one more line than I expect?

If your text ends with a newline character, splitting on line breaks produces one extra, empty entry after the final break, and that trailing entry is counted as a blank line. This matches how many text editors and version control systems treat a file that ends in a newline.

Does the Longest Line stat count invisible characters?

Yes, in one specific case. Text copied from a Windows source with CRLF line endings keeps a trailing, invisible carriage return character attached to each split line, which adds one to that line's counted length even though it isn't visible.

Does a line with only a non-breaking space count as blank?

Yes. The blank check uses JavaScript's .trim(), which strips more than the standard space character — it also removes tabs and any Unicode space-separator character, including the non-breaking space that's a common artifact of pasting text copied from a webpage.

Does the longest-line count match the number of visible characters exactly?

Almost always, but not for lines containing characters outside the Basic Multilingual Plane, such as many emoji. Those are stored internally as two UTF-16 code units, so a line with emoji in it will report as slightly longer than what you'd count by eye.

Is my text uploaded anywhere when I use this tool?

No. All counting happens locally in your browser as you type; nothing is sent to a server, so it's safe to use on private text, logs, or code.