Add Line Numbers

Add line numbers to each line of text with customizable formatting.

About This Tool

Prepends a line number to each line of input text. Configurable starting number, padding character, separator, and zero-padding width. Useful for code review snippets, quoting documents in correspondence, and preparing technical content for print.

Default output uses 4-character right-aligned numbers separated by a single space. Empty lines are numbered by default but can be suppressed. Tabs in source content are preserved.

The tool exists because numbered references in text discussion need stable line counts. "On line 47, the variable name is wrong" is unambiguous only when both parties see the same numbering. Code-review platforms (GitHub, GitLab) handle this implicitly with their own line-number columns; pasting code into email, documents, or chat strips that and necessitates explicit numbering.

Configuration options handle the common variations. Padding width: most line counts are 1–4 digits, so right-aligned 4-character padding looks clean (" 1", "12", "123", "1234"). Padding character: spaces (default) keep the gutter unobtrusive; "0" produces "0001" style which sorts lexicographically as well as numerically. Separator: a single space is the most common choice, followed by " | " for visual separation in monospace, ":" for parser-friendliness (matching git diff and grep output), or " - " for readable prose. Starting number: usually 1, but excerpts from longer files often need to match their original line range.

A worked example. Input three lines: "function add(a, b) {", " return a + b;", "}". Default output: " 1 function add(a, b) { 2 return a + b; 3 }". Compact mode without padding: "1 function add(a, b) {", etc. Code-review style with colon separator: "1: function add(a, b) {". Each format suits a different context: padded for visual alignment, compact for inline references, colon-separated for grep-compatible parsing.

Empty-line handling is a recurring decision point. For code listings, numbering empty lines preserves alignment with the source file's actual line count — line 47 in the snippet matches line 47 in the file. For prose with paragraph spacing, numbering blank lines is clutter; the meaningful units are paragraphs, not lines. The toggle defaults to numbered for code, unnumbered for prose; the user judges the context.

Limitations: very long inputs become expensive in-browser. Adding line numbers to 100,000 lines is the practical limit for browser-based processing; beyond that, command-line utilities (nl, cat -n, awk 'NR{print NR, $0}') handle the volume more efficiently. The tool also does not preserve language-specific syntax highlighting; pasting line-numbered code into a syntax-aware editor strips the line numbers as if they were code, which is usually the desired outcome.

The about text and FAQ on this page were drafted with AI assistance and reviewed by a member of the Coherence Daddy team before publishing. See our Content Policy for editorial standards.

Frequently Asked Questions