Skip to content
Toolew.com

Code Line Counter

Paste source code to count total, code, comment and blank lines, with comment detection tuned for common language syntaxes.

Runs in your browser. Your data is not uploaded.
Loading tool…

Tool guide

What this tool does

Code Line Counter counts total, blank, comment and code lines in pasted source, with a selectable comment-detection mode covering // and /* */ (C-like languages), # (Python/Ruby/Shell/YAML), -- (SQL/Lua), <!-- --> (HTML/XML) and Python’s triple-quoted docstrings.

A raw "lines of code" figure is a blunt instrument, since it lumps actual logic together with blank spacing lines and comments, which can make a heavily-commented, well-formatted file look misleadingly large compared with a dense, comment-free one of similar real complexity.

This counter breaks a pasted file down into total, blank, comment and genuine code lines, using a comment-detection mode you choose to match the language’s syntax: // and block /* */ comments for C-like languages, # for Python, Ruby, Shell and YAML, -- for SQL and Lua, HTML/XML’s <!-- --> blocks, or Python’s combination of # comments and triple-quoted docstrings.

How to use Code Line Counter

  1. Paste your source code into the text box.
  2. Choose the Comment style matching your file’s language.
  3. Read Total lines, Code lines, Comment lines and Blank lines.
  4. Switch the comment style and compare if your file mixes conventions (for example, SQL embedded inside a Python string).

Tips for better results

  • Block comments (/* ... */ or <!-- ... -->) spanning multiple lines are correctly counted as comment lines for every line they cover, not just the line where they start.
  • A line containing both code and a trailing comment (like `x = 1 # set default`) is counted as a comment line by this simple line-based heuristic, since it starts with detecting comment markers per line rather than parsing full language syntax.
  • For a file that genuinely mixes comment conventions (rare, but possible in generated or templated code), run the counter once per relevant style and combine the results manually.
  • This is a line-based heuristic, not a full language parser; it won’t catch every edge case (such as a comment marker appearing inside a string literal), but is accurate for the vast majority of normally formatted code.

Common use cases

  • Getting a quick lines-of-code breakdown for a file before refactoring or reviewing it.
  • Comparing how heavily commented one file is relative to another of similar size.
  • Reporting basic code size statistics for a project status update.
  • Sanity-checking an automated code-metrics tool’s line counts against a quick manual check.

Common mistakes to avoid

  • Expecting full language-aware parsing; this is a line-based heuristic that can miscount an edge case like a comment marker appearing inside a string literal, which a real parser would correctly ignore.
  • Choosing the wrong comment style for the pasted language, which will miscategorise every comment line as code (or vice versa) throughout the file.
  • Treating a line with trailing code-then-comment as pure code; this counter’s per-line heuristic counts it as a comment line once it detects a comment marker anywhere relevant on that line.

Frequently asked questions

Does this parse the language fully, or just scan line by line?

It scans line by line using the chosen comment style’s markers; it is not a full language parser, so rare edge cases like a comment marker inside a string literal can be miscounted.

How are multi-line block comments counted?

Every line a block comment spans, from its opening marker to its closing marker, is counted as a comment line, not just the line where the comment starts.

What happens with a line that has both code and a comment?

This simple per-line heuristic counts it as a comment line once a comment marker is detected on that line, rather than splitting it into a partial code line and a partial comment line.

Which languages are supported?

Comment styles covering C-like languages (JS/TS/Java/C/C++/Go/Rust/CSS), Python/Ruby/Shell/YAML, SQL/Lua, HTML/XML, and Python with triple-quoted docstrings included.

Feedback & suggestions

Help us improve Code Line Counter. We read every message.

Rating (optional)
Necessary
Required for security, language and theme preferences. Always on.