DevKits

Line Counter — Count Lines of Code, Comments & Blank Lines Online

Count total lines, non-empty lines, code lines vs comment lines, and blank lines in any text or source file. Reports longest / shortest / average line length. Optional numbered-line output. 100% local.

Last updated:

194 chars · 11 lines

Total lines

10

Non-empty

8

Code

6

Comments

2

Blank

2

Longest

33 chars

Shortest

0 chars

Average

18 chars

Total chars

184

Total bytes

194

Paste any text or source file to see total lines, non-empty lines, code vs comment lines, blank lines, and longest / shortest / average line length. Toggle 'Number lines' to output the same text with line numbers prefixed.

What is Line Counter?

A line counter classifies each line of text into total / non-empty / code / comment / blank. For source code, the distinction matters: 'lines of code' (SLOC) usually means non-blank, non-comment lines — the metric most tooling (cloc, scc, tokei) reports. This tool uses heuristic comment detection that matches the most common single-line markers across C-style languages, Python/shell, SQL, HTML, and JSDoc — accurate enough for quick estimates, though not a substitute for a language-aware parser on multi-line comments or edge cases like strings that look like comments. It also reports line-length distribution so you can spot outlier lines that break your team's max-line-width lint rule.

How to count lines online

  1. 1Paste text or paste an entire source file into the input pane.
  2. 2Read the metric cards: Total lines, Non-empty, Code, Comments, Blank.
  3. 3Check the length row: longest, shortest, average. Long lines flag files with likely style-guide violations.
  4. 4Toggle 'Number lines' to output the same text with 1., 2., 3. prefixes — useful for bug reports and code reviews.

Use Cases

Quick SLOC estimate for a code review

Paste a diff or a whole file to know how big a change is before committing to review it.

Check if a text pastes as-expected

When copying multi-line data between tools, quickly confirm 'yes, all 1000 rows are here' by comparing counts.

Enforce max-line-width policy

The 'longest line' metric flags lines that exceed the team's 80- or 120-column rule at a glance.

Generate numbered output for docs

Add line numbers before pasting into a bug ticket or blog post — makes referring to 'line 47' possible.

Key Concepts

SLOC (Source Lines of Code)
A standard code-size metric: total non-blank, non-comment lines. Comparable across languages when using consistent rules.
Blank line
A line that is empty or whitespace-only. Excluded from SLOC but often meaningful for readability.

Tips & Best Practices

  • For accurate multi-language SLOC (with block-comment handling), use cloc or scc as a follow-up. This tool is optimized for speed and covers ~90% of quick-check use cases.
  • The 'longest line' number is a great smell test for missing newlines in generated code — if it's in the thousands, something is wrong.
  • Line numbers are added at output time, so the counts reflect the original input regardless of whether numbers are on.
  • Windows CRLF and Unix LF line endings both count correctly — the tool normalizes internally.

Frequently Asked Questions

How does the tool distinguish code lines from comment lines?

Comment detection is heuristic — it looks for common single-line markers (//, #, --, ;, <!--) at the start (after whitespace) of each line. It's accurate for typical source files and adequate for quick stats; for a rigorous per-language SLOC report use cloc or scc.

How is a blank line defined?

A line that is empty or contains only whitespace (spaces, tabs). Blank lines are counted separately from code and comment lines.

Does the tool support very large files?

Yes. Line counting is O(n) and runs on the client, so multi-MB pastes work fine on modern browsers. For files larger than a few MB, consider running cloc locally.

Can I generate text with line numbers prefixed?

Yes — flip the 'Number lines' toggle. You can pick the separator (default ' | '), the starting number, and whether to right-pad numbers for aligned output.

Related Tools