📏 Line Counter

Count total / blank / non-blank / comment / code lines instantly. Detects comments for JS, Python, SQL, HTML, CSS, Shell. Width distribution, longest line, long-line warnings.

What is Line Counter?

A free line counter that breaks down any text or source file into total lines, blank lines, non-blank lines, comment lines, and pure code lines — with built-in comment detection for seven language families: JavaScript / TypeScript / Java / C / C# / Go / Rust (// + /* */), Python / Ruby / Shell (#), SQL (-- + /* */), HTML / XML (<!-- -->), CSS / SCSS, Bash / YAML / Make. View line numbers, see the width-distribution histogram, identify the longest line, and configure a "long line" threshold (default 80 chars) to flag lines that exceed your style limit. Export stats as JSON for code-quality dashboards. Everything runs in your browser — paste, drop, or upload any file. No upload, no signup.

How to Use

  1. Paste text or code, upload a file, or click "Try Sample" for a JS example.
  2. Pick a language preset to enable comment-line detection (Plain text disables comment counting).
  3. Adjust the "long line threshold" slider to match your style limit (default 80).
  4. Toggle "Show numbers" to display line numbers alongside the text.
  5. Read the breakdown — total, non-blank, blank, code, comments, long lines — at the top.
  6. Export the stats as JSON for code-quality reports.

When line counting actually matters

  • Code review effort estimation — a 50-line PR takes 5 minutes to review; a 500-line PR takes an hour and gets less attention per line.
  • Style-guide compliance — most teams enforce a max line width (PEP 8: 79, Google Java: 100, Black formatter: 88). Use the long-line counter to find violations.
  • Document length checks — articles, contracts, and reports often have line-count requirements.
  • Log-file triage — knowing whether a log spans 100 or 100,000 lines tells you how to approach it.
  • Migration planning — moving 5,000 lines of legacy code is a different undertaking than 50,000.
  • Comment-density health checks — a codebase with 0% comments is undocumented; one with 60%+ comments is over-commented or has dead code wrapped in conditional comments.

Why comment detection is approximate

True comment detection requires parsing the language — handling string literals that contain comment markers, escaped quotes, multi-line strings, regex literals. A line-based detector reads one line at a time without understanding the surrounding syntax. The trade-off: line-based runs in milliseconds on 100,000-line files, while a true parser is slower and language-specific.

The errors a line-based detector makes are predictable: false positives (a string containing "//" gets flagged as comment) are rare in practice. False negatives (an end-of-line comment that does not start the line) are more common. For code-quality reports, the approximate count is usually within 5% of the true count.

Width distribution — what healthy code looks like

The width-distribution histogram shows you how lines are distributed across width buckets. Different code styles produce characteristic shapes:

  • Modern, well-formatted code — peak at 30-60 chars, tail to 80, almost nothing above 100.
  • Auto-formatter-applied code (Prettier, Black) — sharp drop-off right at the configured limit.
  • Legacy / hand-formatted code — broad distribution, long tail past 120. Hidden complexity in long lines.
  • Generated code — bimodal: many short lines plus a cluster of very long lines.
  • Plain prose — even spread up to ~80 (typical word-wrap), few short lines.

Frequently Asked Questions

How does comment detection work?

For each language preset, the tool scans for the language's comment markers. Single-line markers (//, #, --) flag lines that start with that marker. Block markers (/* */, <!-- -->) flag every line from the opening marker to the closing marker. Comment-only lines count as "comment"; lines mixing code and trailing comments count as "code" because they execute. The detection is line-based — it does not parse string literals, so a line with a // inside a string will be falsely flagged. For most code-quality reports this approximation is close enough.

What counts as a "code line" (SLOC)?

Source Lines Of Code = non-blank lines that are not comments. So an 800-line file with 150 blanks and 100 pure-comment lines has 550 SLOC. This matches what most LOC tools (cloc, scc, tokei) report under "code". SLOC is a poor proxy for productivity but a useful proxy for code review effort and comparing similar implementations.

Why does my Python script show 0 comments when I have docstrings?

Python triple-quoted strings ("""...""") are not formally comments — they are string literals that the parser ignores at the statement level. The tool treats them as code. To count docstrings as comments, copy them and paste them line by line with leading "#" markers, then re-count. For most metrics work, treating docstrings as code is the more accurate choice.

What is the "width distribution" histogram?

It shows how many lines fall into each character-width bucket: 0-20, 21-40, 41-60, 61-80, 81-120, 120+. A healthy code file usually has most lines in the 21-60 range with a tail to 80; a long tail above 80 suggests overly complex expressions, inline comments that should be moved, or wide string literals.

Why are some lines flagged as "long" when they look fine?

The threshold defaults to 80 characters because that is the most common style-guide limit (PEP 8, GitHub diff width). Many modern teams use 100, 120, or no limit at all. Slide the threshold to match your team's style. Lines containing tabs are counted at 1 character per tab; if your style limit is enforced post-tab-expansion, expand tabs to spaces in your editor first.

Related Tools

  • 📝 Word Counter — Count words, characters, sentences, and paragraphs instantly as you type. Free online word counter with readin
  • 💘 Secret Crush Detector — Party game: everyone secretly picks a crush with a PIN-protected pick, then reveal mutual matches. 100% privat
  • 🎲 Truth or Dare Generator (Smart Mode) — The smartest Truth or Dare generator online. 200+ prompts across 5 group types (friends/couples/office/family/
  • 🤖 ChatGPT Humanizer — De-robotize AI text in your browser. 200+ AI-tell swaps, contraction injection, em-dash cleanup, sentence-vari
  • Aa Case Converter — Convert text between UPPERCASE, lowercase, Title Case, camelCase, snake_case, kebab-case, and more.
  • ¶ Lorem Ipsum Generator — Generate placeholder text in paragraphs, sentences, or words. Perfect for mockups and design work.
  • 📑 Markdown Preview — Write Markdown on the left, see a live rendered preview on the right. Supports headings, bold, code, lists, an
  • 𝓐 Fancy Text Generator — Convert plain text into 40+ Unicode font styles — bold, italic, cursive, bubble, upside-down, Zalgo, and more.

Related: line counter, count lines, lines of code counter, loc counter, sloc counter, count blank lines, count comment lines, longest line finder, line length checker, code line analyzer, text line counter, count rows in file, line width distribution, flag long lines, count comments in code