Skip to main content
Programming Language Tools

Code Line Counter

Count total, blank, non-blank, and comment lines in any pasted code.

Paste your code below - this tool counts total, blank, non-blank, and (optionally) comment lines.

Comment-line detection uses common single-line comment markers (//, #, --) - it's a reasonable approximation, not a full language-aware parser.

What Does This Tool Count?

Total line count, blank lines, non-blank lines, and (based on common comment markers like //, #, or --) an estimate of comment-only lines.

Why Use This Tool?

A quick, practical way to gauge a file's size or estimate how much of it is actual code versus comments/whitespace, without needing to open it in an IDE with a line-count feature.

How to Use It

  1. Paste your code.
  2. Click Count.
  3. Review the total/blank/non-blank/comment line breakdown.

Limitations

Comment detection looks for common single-line comment markers at the start of a trimmed line - it doesn't parse multi-line block comments or understand any specific language's full comment syntax perfectly.

Example

# load settings
import json

def load(path):
    # read the file
    with open(path) as f:
        return json.load(f)

gives 7 total lines: 1 blank, 6 non-blank, of which 2 are comment lines - so 4 lines of actual code.

What Line Counts Are Good For

  • Estimating the size of a file before a code review or refactor.
  • Checking comment density - a large function with no comments, or one that is half commented-out code.
  • Quick numbers for a report, a quote or a portfolio.

What They Are Not Good For

Lines of code measure size, not quality or effort. Ten careful lines can be harder to write than two hundred generated ones, and the same logic can take very different line counts in different styles. Use counts to compare files within one project, not to judge people.

Counting a Whole Project

For a whole repository, command-line tools such as cloc, tokei or scc count every file by language and skip vendor folders.

Clean up before counting with the Code Comment Remover or the Code Beautifier.

Frequently Asked Questions

Choose the comment style for your language - // (JavaScript, PHP, C-style) or # (Python, shell, YAML) - and lines starting with that marker are counted as comments. Block comments and comments at the end of a code line count as code.

Non-blank, non-comment lines give a rough idea of code size, but line counts are not a measure of quality or effort.

This tool counts pasted code. For whole repositories use a command-line tool such as cloc or tokei.
Share this tool: