Line Counter — Count the Number of Lines in Text or Code
Line Counter
Paste text or code and watch every metric update in real time.
How to use this line counter
Start typing or paste your content into the input box. The tool splits your input on newline characters (\n) and updates every metric — total, non-blank, blank, code, comments, words, characters, sentences, paragraphs and averages — as you type. Switch to Non-blank to exclude empty lines, or Code lines to strip out comment lines using the syntax of a specific programming language.
The Load sample button drops in an example JavaScript snippet so you can see code-line detection in action. Copy stats copies a formatted summary of all metrics to your clipboard, and Clear resets the input. Everything runs locally in your browser — nothing is uploaded, cached on a server, or written to disk.
What is a line counter?
A line counter is a text utility that counts the number of lines in a block of text by counting newline separators. On most systems a line ends with a line-feed character (\n) on Unix and macOS, or a carriage-return-plus-line-feed pair (\r\n) on Windows. A line counter normalizes those separators, splits the text, and reports the resulting count along with related statistics like words, characters, sentences and paragraphs.
Line counters are used by writers to check manuscript length, by developers to measure the size of source files, by teachers to enforce assignment limits, and by data engineers to sanity-check CSV row counts before running a pipeline. Because line counting is the foundation of nearly every text-processing tool — from wc on the command line to Word’s built-in stats — a fast, accurate browser-based counter is one of the most-searched utilities on the web (Miniwebtool).
How to count the number of lines in a text file
There are four common ways to count lines in a file. Each returns the same answer for a well-formed text file that ends with a newline:
- Paste it into this line counter. Instant, offline, works on any device, and gives you every related metric in one view.
- On Linux or macOS use
wc -l. The classic Unix command reports the number of newline characters:wc -l file.txt. - On Windows use PowerShell. Run
(Get-Content file.txt | Measure-Object -Line).Linesto count lines exactly likewc(Microsoft Learn). - Inside VS Code, select all the text and the status-bar readout shows both selection length and cursor position (Ln X, Col Y).
wc -l counts newline characters, not lines. A file that ends without a trailing newline reports one fewer line than a text editor would show. This line counter treats trailing content as its own line, matching the behavior of Word, Google Docs and VS Code.Total lines vs non-blank lines vs code lines
The three counting modes solve three different problems, and the difference between them matters:
| Mode | Definition | Best for |
|---|---|---|
| Total lines | Every line separator in the input, including empty lines and comment lines. | Manuscript length, CSV row counts, log-file scanning. |
| Non-blank lines | Lines containing at least one non-whitespace character. | Poetry, screenplays, résumé line limits, “real content” checks. |
| Code lines | Non-blank lines that are not classified as comments, based on the selected language’s syntax. | Software estimation, LOC reports, codebase comparisons. |
For plain prose, total and non-blank are usually the two numbers you care about. For source code, code lines is the industry-standard measure known as Source Lines Of Code (SLOC) and is defined by GeeksforGeeks as “non-blank, non-comment lines including declarations and statements.”
Every metric the line counter reports
Beyond the raw line count, this counter exposes 14 statistics — every one available at a glance in the results panel:
- Total lines — every line separator including blanks.
- Non-blank lines — lines with at least one visible character.
- Blank lines — empty lines or lines containing only whitespace.
- Code lines — non-blank, non-comment lines in the selected language.
- Comment lines — lines detected as comments by language syntax.
- Words — runs of non-whitespace characters.
- Characters with spaces — total characters including whitespace.
- Characters without spaces — total characters ignoring whitespace.
- Sentences — runs of text ending in
.,?or!. - Paragraphs — groups of non-blank lines separated by blank lines.
- Average line length — total characters ÷ non-blank lines.
- Average words per line — total words ÷ non-blank lines.
- Longest line — the line number and character length of the longest line.
- Shortest non-blank line — the line number and character length of the shortest non-blank line.
How code-line counting and comment detection work
When you pick a language, the counter classifies each line into one of three categories using both single-line comment prefixes and multi-line block comment pairs. Block comments are tracked with a state machine so a comment that spans multiple lines is fully recognized. The table below lists every supported language and its comment syntax:
| Language | Line comment | Block comment |
|---|---|---|
| Python | # | """ ... """ or ''' ... ''' |
| JavaScript / TypeScript | // | /* ... */ |
| Java, C, C++, C#, Go, Rust, Swift, Kotlin | // | /* ... */ |
| PHP | // or # | /* ... */ |
| Ruby | # | =begin ... =end |
| SQL, Lua, Haskell | -- | /* ... */ (SQL only) |
| Bash / Shell | # | — |
| HTML / XML | — | <!-- ... --> |
| CSS / SCSS | // (SCSS only) | /* ... */ |
| LaTeX, MATLAB / Octave | % | — |
| Assembly, INI | ; | — |
// comment — are classified as code, matching the widely used cloc convention.Common use cases for a line counter
- Writers & editors — verify manuscript, article and essay length when submissions have line limits (poetry contests, some literary magazines, script coverage services).
- Developers & engineering managers — measure lines of code (LOC), calculate comment-to-code ratios, and estimate effort using function-point or COCOMO models.
- Students & teachers — check that homework, assignments and take-home exams meet line-count requirements before submission.
- Data analysts — quickly count the number of rows in a CSV, TSV or log file before loading it into pandas, Excel or a SQL database.
- SEO & content marketers — evaluate readability by looking at average line and paragraph length; long walls of text hurt engagement.
- Translators & localizers — quote projects that price by line, common in subtitle localization and legal translation.
- Log & ops engineers — sanity-check the size of grep output, error logs or configuration files.
Line counter vs word counter vs character counter
The three counters look similar but answer different questions. A word counter measures the number of whitespace-separated tokens — useful for essays, articles and Twitter/X posts. A character counter counts glyphs including or excluding spaces — indispensable for SMS, meta descriptions and social bios where hard character limits apply. A line counter measures structure: how many lines, how many blanks, how many paragraphs. In practice most writers open all three in tandem; that is why this counter surfaces every metric on a single page.
Why lines of code (LOC) is useful — and why it isn’t a productivity metric
LOC is a size metric, not a quality or productivity metric. Counting non-blank, non-comment lines gives you a rough sense of scope and helps compare modules, but it says nothing about correctness, readability or business value. A programmer who deletes 500 duplicate lines produces “negative LOC” while making the codebase healthier (DX, NDepend).
Modern engineering teams use LOC alongside more meaningful indicators — cycle time, deployment frequency, change-failure rate, code coverage and defect density — as recommended by the DORA metrics framework. Use this counter to understand size and structure; combine it with these other signals when judging code health.
Frequently asked questions
How do I count the number of lines in a text file?
Paste the file’s contents into this counter, or use wc -l file.txt on Linux/macOS or (Get-Content file.txt | Measure-Object -Line).Lines in PowerShell. All three approaches count newline characters plus a trailing non-empty line.
What is the difference between total lines and non-blank lines?
Total lines counts every line separator in the file, including empty lines. Non-blank lines counts only lines with at least one non-whitespace character.
How does the code line counting mode work?
Each line is checked against the selected language’s line-comment prefixes (#, //, --, %, ;) and block-comment pairs (/* */, <!-- -->, """ """). Blank lines and comment lines are subtracted from the total, and the remainder is the code line count — the industry-standard SLOC measure.
What is LOC in software engineering?
LOC stands for Lines Of Code. It is a volume metric used for size estimation, effort modeling (for example, COCOMO) and comparing codebases. It is not a reliable measure of developer productivity on its own.
Does the line counter store or upload my text?
No. Every calculation runs in your browser using client-side JavaScript. Your text is never uploaded to a server, saved to a database, or shared with third parties.
Can I count lines in a Word document or PDF?
Yes — open the document, copy the text, and paste it into the counter. Because Word and PDF wrap paragraphs across visual lines, the counter reports logical lines (paragraph breaks and hard newlines), not visual lines rendered on the page.
How is a paragraph counted?
A paragraph is one or more consecutive non-blank lines separated by at least one blank line. This matches the definition used by Microsoft Word, Google Docs and most editors.
What counts as a sentence?
Any run of text terminated by a period (.), question mark (?) or exclamation mark (!). The counter ignores common abbreviations such as Mr., Dr., Inc., and etc. to reduce false positives.
Which programming languages are supported?
Python, JavaScript, TypeScript, Java, C, C++, C#, Go, Rust, PHP, Ruby, Swift, Kotlin, SQL, Bash, HTML, XML, CSS, SCSS, Lua, Haskell, LaTeX, MATLAB, Octave, Assembly and INI files.
Is there a limit on how much text I can paste?
There is no hard limit, but the counter is optimized for text up to a few megabytes. For very large inputs, changes are debounced so your browser stays responsive.
Sources & methodology
- Microsoft Learn — Measure-Object cmdlet — learn.microsoft.com
- GeeksforGeeks — Lines of Code (LOC) in Software Engineering — geeksforgeeks.org
- DX — Why lines of code fall short as a productivity metric — getdx.com
- NDepend — How to Measure Lines of Code — blog.ndepend.com
- cloc — Open-source tool for counting blank, comment and code lines — github.com/AlDanial/cloc
Line boundaries are detected using the JavaScript regular expression /\r\n|\r|\n/, matching the LF, CR, and CRLF conventions used across Unix, macOS and Windows. Code-line classification follows the widely adopted cloc convention: a line containing any non-comment code is counted as a code line, even if it also carries a trailing inline comment.