Code Line Counter

Count total lines, code lines, comment lines, and blank lines. Auto-detects language from comment syntax.

Input Code
Results

Results will appear here after you paste code.

Paste code above to count lines.

How to Use the Code Line Counter

  1. Choose a language — or leave it on Auto-detect and the tool will identify the comment syntax.
  2. Paste your code — the results update instantly as you type.
  3. Read the breakdown — total, code, comment, and blank line counts with percentage bars.
  4. Download the report — save a plain-text summary for documentation.

What the Counts Mean

Most code metrics tools classify each line into one of three categories. This counter follows the same standard definitions used by tools like cloc and tokei.

Blank Lines

A blank line contains only whitespace characters (spaces, tabs) or is completely empty. Blank lines are first in the counting hierarchy — a line that contains only whitespace is always counted as blank, never as code or comment.

Comment Lines

A comment line (after stripping leading whitespace) starts with a comment delimiter — // for JavaScript/Java/C#/CSS, # for Python, <!-- for HTML — or is inside an active block comment. Multi-line block comments (/* ... */ in C-style languages, """ ... """ in Python, <!-- ... --> in HTML) are tracked across lines using a state flag.

Code Lines

Any non-blank, non-comment line is counted as a code line. Lines that contain both code and an inline comment (e.g., return true; // always) are counted as code lines, not comment lines. This matches the behavior of standard tools like cloc.

Language Support

The auto-detect algorithm inspects the first 30 lines for tell-tale patterns. HTML is recognized by <!DOCTYPE> or common HTML tags. Python is identified by def, class, import statements and #-prefixed comments. CSS is detected by selector/property patterns and /* */ comments. JavaScript and Java/C# share C-style comment syntax but are distinguished by keywords like function, var, let, const (JS) versus class, public, void, namespace (Java/C#).

Practical Uses for Line Counts

Code line counts are useful in many professional contexts. Project managers use them to estimate code complexity and size for planning. Developers use comment ratios to evaluate documentation quality before code reviews. Some organizations track lines of code (LOC) as a rough proxy for technical debt — though this metric must be interpreted carefully, as fewer, well-crafted lines often indicate higher quality than more verbose code. For historical analysis across a full codebase, command-line tools like cloc (Count Lines of Code) or tokei (Rust-based, very fast) are recommended. For single-file analysis in a browser without installing anything, this tool is the fastest option. See related tools: Indent Converter, Diff Checker.

Frequently Asked Questions

A blank line contains only whitespace. A comment line contains only a comment (after trimming whitespace). A code line contains actual executable or declarative code — it may also have an inline comment, but if any code exists on the line it is counted as a code line.
Auto-detect looks for tell-tale patterns in the first 30 lines. HTML is detected by DOCTYPE or HTML tags. Python by def/class/import patterns and hash comments. CSS by selector/property patterns. JavaScript and Java/C# are distinguished by common keywords and syntax patterns.
The line counter works at the line level, not the AST level. Lines inside multi-line strings are counted as code lines even if visually empty. For production-grade counts, use a dedicated tool like cloc or tokei.
There is no single correct ratio, but 10-30% comment lines relative to total lines is commonly cited as healthy. Very low comment density may indicate under-documented code. Very high density can indicate over-commenting obvious code. The best comments explain why, not what.
No. The code line counter runs entirely in your browser. Your code never leaves your machine. There is no server processing, no logging, and no data storage.