Works on this device
Code Line Counter
Paste code, or choose files or a whole folder from your device. The page counts the lines of each file as code, comment or blank lines, and adds them up by language. The files are read in your browser and are not uploaded.
Count pasted code
Paste or type code. It is counted on this device and not sent anywhere.
- Lines
- 0
- Blank lines
- 0
- Comment lines
- 0
- Code lines
- 0
Count files on your device
Up to 1,000 files, 5 MB each and 50 MB in all. The files are read in this browser and are not uploaded. Your browser may ask you to confirm a folder.
Ready. Choose files or a folder to count them.
Lines in your files
Choose files or a folder to see their lines here.
- Files counted
- 0
- Lines
- 0
- Blank lines
- 0
- Comment lines
- 0
- Code lines
- 0
| Language | Files | Lines | Blank | Comment | Code |
|---|
| File | Language | Lines | Blank | Comment | Code |
|---|
| File | Why |
|---|
How to count lines of code
- To count pasted code, choose its Language and paste the code. The four counts change as you type.
- To count files, choose Choose files (you can pick many at once) or Choose a folder. The language of each file comes from the end of its name.
- Read the totals, the table By language and the table By file. Files that were left out are listed with the reason.
- Choose Download CSV to keep the tables, or Copy the summary to paste the totals.
How each line is counted
- A line ends at a line break. A line break at the very end of a file does not start another line, so a file of three lines with a final line break has 3 lines.
- A blank line has nothing on it but spaces and tabs.
- A comment line has a comment and nothing else but spaces and tabs. A line inside a comment that runs over several lines is a comment line too.
- A code line is every other line. A line with code and a comment after it, such as
x = 1 # one, is a code line. - Comments are found with the same small readers as the Syntax Highlighter, so a
//or#inside text in quotes is not taken for a comment. - A Python docstring (
"""…""") is text in quotes, so its lines are code lines. Some other counters count docstrings as comments. - In HTML the comments of
<script>and<style>count too. In Markdown,<!-- -->comments and the comments inside fenced code of a language on the list count as comment lines. JSON has no comments, and in plain text every line that is not blank is counted as a code line.
| Language | Comments |
|---|---|
| JavaScript | // to the end of the line; /* to */ |
| TypeScript | // to the end of the line; /* to */ |
| JSON | none (JSON has no comments) |
| HTML | <!-- to --> |
| XML (also SVG) | <!-- to --> |
| CSS | /* to */ |
| SCSS | // to the end of the line; /* to */ |
| SQL | -- to the end of the line; /* to */ |
| Python | # to the end of the line |
| PHP | // and # to the end of the line or to ?>; /* to */ |
| Java | // to the end of the line; /* to */ |
| C | // to the end of the line; /* to */ |
| C++ | // to the end of the line; /* to */ |
| C# | // to the end of the line; /* to */ |
| Go | // to the end of the line; /* to */ |
| Kotlin | // to the end of the line; /* to */ (these may be inside each other) |
| Bash (shell) | # at the start of a word, to the end of the line (also the #! first line) |
| YAML | # at the start of a line or after a space |
| Markdown | <!-- to --> |
| GraphQL | # to the end of the line |
Which files are counted
- Files whose names end with: JavaScript (.js, .mjs, .cjs); TypeScript (.ts, .mts, .cts); JSON (.json); HTML (.html, .htm); XML (.xml, .svg, .xsd, .xsl, .xslt); CSS (.css); SCSS (.scss); SQL (.sql); Python (.py, .pyw); PHP (.php); Java (.java); C (.c, .h); C++ (.cpp, .cc, .cxx, .hpp, .hh, .hxx); C# (.cs); Go (.go); Kotlin (.kt, .kts); Bash (.sh, .bash); YAML (.yaml, .yml); Markdown (.md, .markdown); GraphQL (.graphql, .gql). A
.hfile is read as C. - Files with other endings are left out, unless you tick Count files with other endings as plain text.
- When Leave out tool and build folders is ticked, files inside folders named
.git,node_modules,vendor,dist,build,__pycache__,.venvare left out. This is useful when you choose a whole project folder. - A file that is not UTF-8 text (for example a picture or a program) is left out with a note.
Worked example
The Python example of the page has 12 lines: the first line #!/usr/bin/env python3 and the line # The vowels we look for are comment lines (2), the docstring line, VOWELS = set("aeiou"), the def line with its comment, the return line and the print line are code lines (5), and 5 lines are blank. 5 code lines of 12 lines is 41.7%.
Limits you should know
- Up to 1,000 files, 5 MB for each file and 50 MB in all. Pasted code up to 1,000,000 characters.
- A line count says how long code is, not how good it is or how much work it took.
- The readers follow simple stated rules. Unusual code, such as a comment mark inside a PHP heredoc text, can be counted in a way another counter would not count it.
- Lines are not counted by function, by author or by change. This page does not read a project from an address or a code hosting site; choose the folder on your device.
- To count words, characters and lines of ordinary text, use the Word Counter.