Line Counter
Count total lines, blank lines and get line statistics.
Reviewed by Aygul Dovletova · Last reviewed
How to Use the Line Counter
- Paste your text into the input box. Source code, CSV exports, log files, essays, and chat transcripts all work fine.
- Read the summary cards that update in real time: total lines, non-empty lines, blank lines, average line length, longest line length, and shortest non-empty line length.
- Compare the non-empty and total counts to see how much of your file is padding. A ratio above 30 percent blank often means inconsistent newline handling somewhere upstream.
- Use the longest-line metric to catch wrap-breaking rows in code or CSV data - a 2000-character line almost always signals missing newline normalization.
- Copy the metrics if your CI report or code review needs the numbers, or just read them off the screen.
How the Counter Works
Counting starts with input.split(/\\r?\\n/), which splits on either Unix LF or Windows CRLF line endings and produces an array of lines. The total count is the array length; the non-empty count is arr.filter(l => l.trim().length > 0).length, and blank count is the difference. Longest and shortest are one pass each over the array taking Math.max and Math.min of line lengths. Average is totalChars / totalLines rounded to a whole number. Character length here is JavaScript's string.length, which is UTF-16 code units - close to but not exactly the same as user-perceived characters; see the string-length calculator on this site for the distinction. All math happens in the browser tab with no network activity and no service worker interference.
When You Would Use It
- Checking the line count of a code file to decide whether to split it - many team style guides cap modules at 500-1000 lines.
- Validating that a CSV export produced the expected row count before you import it into your database.
- Estimating the size of a poem, script, or screenplay where one line equals one beat.
- Debugging why
wc -lon your system reports a different number than the editor (almost always a missing final newline). - Measuring a pull-request description's length against a corporate policy that limits PR bodies to a certain line count.
- Spotting a giant stringified-JSON line buried in a log file by noticing the longest-line metric is wildly disproportionate.
Common Pitfalls and Edge Cases
- The final newline. A file that ends with
\\nhas one more line than its visible row count becausesplit('\\n')produces an empty string after the trailing newline. This tool reports that extra blank line, matching the POSIX definition where a line must end in a newline. - CRLF vs LF. The regex
/\\r?\\n/handles both cleanly. If your file uses classic Mac\\r-only line endings (rare post-2000 but still possible from some legacy exports) every line will appear as one giant line. - Blank line definition. A line containing only spaces or tabs counts as blank here. If you prefer the strict definition where blank means zero bytes, subtract lines that are truly empty - they are a subset of what is reported.
- Non-ASCII lengths. A line containing emoji or CJK ideographs may have a string length that does not match its visible width. The string-length calculator on this site reports grapheme clusters if that matters for your use case.
- Very long single-line input. If someone pastes a minified JavaScript bundle as one line, the total-line count is 1 and longest is millions; the tool handles this, but your browser's textarea may lag.
What "Line" Actually Means
In POSIX (IEEE Std 1003.1) a line is defined as zero or more non-newline characters followed by a newline, which is why wc -l reports zero for a file without a trailing newline - that trailing content is technically an "incomplete line." Editors and IDEs differ: VS Code and most modern editors show that trailing content as the last line and automatically add a newline when saving if the setting is on. Unicode defines several characters that may act as line boundaries: \\n (LF, U+000A), \\r (CR, U+000D), \\r\\n (CRLF), \\v (vertical tab, U+000B), \\f (form feed, U+000C), U+0085 (next line), U+2028 (line separator), and U+2029 (paragraph separator). JavaScript's regex /\\r?\\n/ is intentionally narrow and handles only the common cases - which matches what your IDE, Git, and most build tools treat as a line.
Comparison to Alternatives
wc -l file is the definitive Unix count and runs at native speed; it counts newlines, so an unterminated final line is not counted, which catches the classic "missing trailing newline" case. awk 'END {print NR}' counts the same way but prints before exit. VS Code's status bar shows line and column of the caret and the total on hover. For CSV row counting, a CSV-aware tool like csvkit's csvstat is safer because it respects quoted newlines inside cells - something a naive newline split (including this tool) mishandles. Use this web counter when you have a short-to-medium paste and want multiple metrics at once, or when you are not in a shell and cannot run wc. For multi-gigabyte log files, stick with wc -l, which finishes in under a second on a terabyte-scale SSD.
Frequently Asked Questions
Why does wc -l say one less than this tool?
Because POSIX wc -l counts newline characters, and a file without a trailing newline produces one fewer newline than the visible number of lines. This tool splits on newlines and returns the array length, so it counts the final non-terminated content as a line. Both interpretations are valid - POSIX is stricter about what qualifies as a "line", this tool matches what you see in your editor. Either way, the delta is always at most one.
Does the counter consider a single-space line as blank?
Yes. A line is classified as blank when its trimmed length is zero, so a line containing only spaces, tabs, or other whitespace characters from Unicode\s counts as blank. If you prefer the stricter definition where blank means literally empty, you will need to preprocess; that subset is always smaller than what this tool reports as blank.
How does the counter handle mixed CRLF and LF?
The split regex /\r?\n/ accepts both kinds of line ending in the same input, so a file exported from Windows and concatenated with Unix-produced content counts correctly. A line that ends with \r only (without a following \n) is not split, which is the right call for modern files but can surprise you if you are dealing with legacy Mac Classic text - that last case is practically extinct today.
Is the counting done entirely in my browser?
Yes. The split, filter, and reduce operations all run in the JavaScript engine of your current tab without any network activity. There is no fetch, no beacon, and no service worker capturing the input. Closing the tab or navigating away releases the text from memory. You can demonstrate this by opening DevTools and watching the Network panel while you paste - nothing appears.
What is the longest line I can paste without slowing the browser?
A single line of a few megabytes is fine on desktop browsers. Beyond that the textarea rendering becomes the bottleneck, not the counter itself. For files with enormous minified lines (compiled JS bundles, one-line JSON dumps), expect your browser tab to become sluggish; the line count still computes correctly in a few milliseconds. For truly giant inputs, wc and awk on the terminal are better suited.
How does average line length get calculated?
Sum of the JavaScript string length of every line divided by the total line count, rounded to a whole number. Because string length counts UTF-16 code units rather than visible grapheme clusters, a line containing an emoji family made of four ZWJ-joined code points will contribute more than one character per visible glyph. For prose-heavy or emoji-heavy text, the grapheme metric reported by the string-length calculator on this site is more intuitive.
Can I count lines of code with this?
Yes, but it counts every line including comments, blank lines, and import statements. For a proper logical-lines-of-code count you want a tool like cloc, tokei, or scc, which understand comment syntax and language structure. For a quick ballpark of file size this tool is fine; for actual complexity or productivity metrics, use a language-aware counter.
Why does the shortest-line metric sometimes show 1 instead of 0?
The shortest-line calculation excludes blank lines by design, because the usefully-short answer is the shortest line that contains actual content. If it said 0 for files with any blank line, the metric would be uninformative. If you want the absolute shortest including blanks, the answer is 0 whenever there is any blank line.
How does this differ from the word counter?
This tool counts lines, which are segments separated by newlines; word counters tokenize on whitespace to count discrete words. They answer different questions: lines measure how long your file is structurally, words measure how much content is in it. A 100-line file can have a different word count depending on line length. Use both if you are sizing a document for an editor or publication.
Does the tool count an empty file as zero lines?
Yes. An empty input produces an empty split array, which has length zero. A single newline character produces an array with two empty strings, so it reports two lines - both blank. That matches the behavior of editors that display a single blank line at the top of an otherwise-empty file.
More Text Tools
Binary to Text
Convert text to binary and binary back to text.
Open toolCase Converter
Convert text between UPPER, lower, Title, Sentence, camelCase, snake_case and more.
Open toolCharacter Counter
Count characters with platform-specific limits for Twitter, Instagram and more.
Open toolEmoji Picker & Search
Search and copy emojis by name or category.
Open toolFancy Text Generator
Generate stylish text with bubbles, squares, upside down and more for social media.
Open toolFind & Replace
Find and replace text with regex support and case-sensitive options.
Open tool