Code Line Counter
Analyze source code to count total lines, empty lines, and comments.
Count lines of code, comments and blank lines
Code Line Counter reads a block of source code and splits its lines into four groups: total lines, code lines, comment lines and empty lines. Lines of code is a rough but widely used measure of size, useful when estimating the effort of a review, filling in a report, or checking how much of a file is documentation rather than logic. You paste the code, press one button and get the breakdown in a table.
How to use it
- Paste your source code into the Input Data box. The Sample button loads a small script with a block comment, a line comment and a blank line.
- Press Process Now. Pressing it with an empty box shows an error asking for code.
- Read the result table: Total Lines, Code Lines, Comment Lines and Empty Lines.
- Use Copy or Download to save the table text as result.txt, or Clear to start over.
How each line is classified
- A line that is blank or contains only whitespace counts as empty.
- A line that begins with /* starts a block comment. That line and every following line up to the one containing */ are counted as comments.
- A line that begins with //, # or the opening of an HTML comment is a comment line.
- Everything else is a code line, including lines where code is followed by a trailing comment.
The four numbers always add up to the total, because each line is placed in exactly one group.
Where it helps
- Reporting the size of a script in a README, ticket or assignment.
- Checking how heavily a file is commented before a code review.
- Comparing the size of two implementations of the same function.
- Trimming a snippet to fit a length limit in a form or exam answer.
Edge cases to watch
The rules are deliberately simple. A line starting with a hash is treated as a comment, which suits shell, Python and Ruby but means C preprocessor lines such as an include and CSS selectors that begin with an id are counted as comments. A multi-line HTML comment only has its first line counted as a comment, and Python docstrings are seen as code. A final newline at the end of your paste adds one extra empty line to the total. For an exact figure across a whole project, use a command-line tool, and use this page for quick checks on a single snippet.
Related Tools