How to use the line counter
- Paste code or text into the Code box. The sample is a short JavaScript file.
- Leave Comment syntax on Detect, or choose one:
//and/* */,#,--and/* */(SQL),<!-- -->,--(Lua, Haskell) or No comments. - Read the counts: Total lines, Code lines, Comment lines, Blank lines, Characters, Longest line, Average line and the Comment syntax used.
What it does and when to use it
Line counts answer quick questions: how big is this function, how much of a file is comments, does a snippet fit a “max 50 lines” rule, or which line breaks an 80- or 120-column limit. The code/comment split helps when you review documentation coverage or estimate effort for a port. Longest line shows at once whether any line is too wide for your style guide.
To remove the blank lines it finds, use the blank line collapser. The whitespace normalizer fixes trailing spaces and line endings, and the code diff viewer counts added and removed lines between two versions.
How it works
The text is split into lines (CRLF, CR and LF all count as breaks). Each line is then read character by character with the chosen comment rules, and the counter keeps track of whether it is inside a string or an open block comment:
- A quote starts a string, so
//or#inside a string is not a comment. The sample’s"https://api.example.com//users"is counted as code. /*or<!--opens a block comment that can span lines; every line inside it is a comment line.- Any other non-space character makes the line a code line.
Characters are counted as visible characters, so an emoji counts as one, and line breaks are included. Everything happens in your browser.
Worked examples
These are the tool’s own outputs.
The JavaScript sample. 10 lines: 5 code, 4 comment (one // line and a three-line /* */ block) and 1 blank. The line with // not a comment start after code counts as code. Its longest line is 70 characters.
A Python script. With a shebang, a # Count words comment, two blank lines and a docstring, the result is Total 8, Code 4, Comment 2, Blank 2, and Detect picks hash.
A SQL query. -- monthly report followed by a three-line query is detected as sql: 3 code lines and 1 comment line. The /* paid only */ after FROM orders does not make that line a comment.
HTML. A one-line <!-- header --> and a three-line comment block give 4 comment lines and 3 code lines.
Limits and tips
- Detect is a guess. Shell scripts with
--options or SQL inside strings can fool it; set the syntax by hand. - Nested block comments are not tracked; the first
*/closes the comment. - Strings across lines are followed only for backtick template literals.
Frequently asked questions
How is a line with code and a comment counted?
Are Python docstrings counted as comments?
Does a trailing newline add a line?
How does Detect choose the comment syntax?
Can it count a whole project?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.