Count total, blank, comment, and code lines in any pasted code with language auto-detection.
正在加载工具…
关于此工具
The Code Line Counter analyses pasted source code and breaks it down into four categories: total lines, blank lines, comment lines, and actual code lines. It automatically detects the programming language based on syntax patterns and applies the correct comment rules — double-slash (//) for JavaScript, TypeScript, Java, C, C++, C#, and Swift; hash (#) for Python, Ruby, Shell, and YAML; double-dash (--) for SQL and Lua; block comments (/* … */) for C-family languages; and HTML/XML comments (<!-- … -->). Results are displayed with progress bars showing the proportion of each line category, making it easy to gauge comment density and blank-line ratio at a glance. Useful for code review, metrics reporting, estimating documentation coverage, or satisfying coding standards that require a minimum comment ratio.
使用方法
1Paste your source code into the textarea.
2The tool auto-detects the language and displays a label.
3Override the language using the dropdown if detection is incorrect.
4Read the four counters: Total, Blank, Comment, and Code lines.
5Check the progress bars to visualise the proportion of each category.
常见问题
A line is counted as a comment if, after trimming leading whitespace, it starts with a comment marker for the detected language (e.g. //, #, --, <!--) or falls entirely within a block comment (/* … */ or <!-- … -->). Inline comments on code lines do not make the line a comment line.
A line that contains only whitespace (spaces, tabs, or is completely empty) is counted as blank.
The tool scans the pasted code for characteristic patterns: shebang lines, common keywords, import/def/function syntax, and comment styles. It assigns a confidence score to each candidate language and picks the highest scoring match. You can also override the detected language manually.
LOC (Lines of Code) is the count of non-blank, non-comment lines — the executable or declarative statements in the file. It is a rough proxy for code complexity and is used in metrics like comment density (comment lines / total lines) and code churn.
You can paste the concatenated content of multiple files into the textarea. The counters reflect the aggregate totals. For per-file stats, paste each file separately.
{# Alpine.js — self-hosted. (The previous jsdelivr CDN tag had a stale SRI
integrity hash, so the browser refused to run it and window.Alpine was
never defined — silently breaking every FAQ accordion and Alpine tool.) #}