Add Line Numbers
Text ToolsPrepend line numbers to every line of text with configurable starting number, padding width, and separator.. Free, private — all processing in your browser.
The Add Line Numbers tool prepends sequential numbers to every line of pasted text. Numbered output makes text easier to reference precisely — \"see line 42\" is clearer than \"the line about connection timeout near the top\". Code snippets in documentation, legal contracts, verse references, log excerpts, and any text that needs specific-line references all benefit from visible line numbers.
This tool gives fine control over how the numbers appear. Choose the starting value (1 is typical, but 0, 100, or a custom offset works). Configure zero-padding width so lines 1-99 still align visually (01, 02, ..., 99). Pick the separator between number and line content — colon, space, period, tab, or a custom string. Skip blank lines from numbering, or include them (classic line-number behavior vs continuous content numbering). Control whether to number lines starting with comments, whitespace, or specific prefixes. All options update the live preview so you see exactly what the output will look like before copying.
Add Line Numbers — key features
Configurable start number
Begin numbering from 1, 0, or any custom integer for showing snippets from specific line ranges.
Auto or manual padding
Zero-pad numbers automatically based on total line count, or set a fixed padding width manually.
Custom separator
Use colon, space, pipe, tab, or any string between the line number and the line content.
Skip blank lines
Toggle whether blank lines receive numbers (continuous per-line) or are skipped (content-line numbering).
Prefix exclusion
Exclude comment lines or other prefixes from numbering via a simple pattern match.
Strip existing numbers
Detect and remove prior line numbers before renumbering, preventing double-prefixes.
Live preview
Output updates as you change options, so you see the result immediately.
Client-side only
Text stays in your browser — safe for confidential code or documents.
How to use the Add Line Numbers
- 1
Paste text
Drop the text into the input area. Any size works.
- 2
Set starting number
Default is 1. Change it for showing snippets starting from a specific line number.
- 3
Pick separator
Choose colon, space, pipe, tab, or enter a custom separator.
- 4
Configure padding
Leave auto for variable-width padding based on total lines, or set a fixed width.
- 5
Copy
One-click copy the numbered output to your clipboard.
Common use cases for the Add Line Numbers
Documentation
- →Code samples: Add line numbers to code snippets in technical documentation so readers can reference specific lines in explanations.
- →Legal documents: Number every line or paragraph in a contract to enable precise references in discussion or negotiation.
- →Verse or text citations: Add line numbers to poetry or prose excerpts for scholarly citation and discussion.
Development
- →Error reporting: Include line numbers in error reports or bug tickets so readers can jump to the specific lines in question.
- →Code review annotations: Paste a code snippet with line numbers into a review tool or ticket for clearer discussion.
- →Log excerpt sharing: Add numbers to log excerpts when sharing them in chat or tickets.
Teaching and training
- →Programming lessons: Number lines in code examples so students can follow along with specific references to line 7 or line 12.
- →Reading comprehension: Add numbers to text passages for discussion questions that reference specific lines.
- →Procedure manuals: Number steps or paragraphs for clear cross-referencing in training materials.
Add Line Numbers — examples
Default numbering
Starting at 1 with colon separator.
first line second line third line
1: first line 2: second line 3: third line
Zero-padded
Two-digit padding for small line counts.
apple banana cherry
01: apple 02: banana 03: cherry
Start from 100
For showing a snippet from a larger file.
function foo() {
return 42;
}100: function foo() {
101: return 42;
102: }Pipe separator
Using a padded pipe.
line A line B line C
1 | line A 2 | line B 3 | line C
Skip blank lines
Only content lines receive numbers.
paragraph 1 paragraph 2 paragraph 3
1: paragraph 1 2: paragraph 2 3: paragraph 3
Technical details
Adding line numbers is trivial in principle: iterate lines, prepend the index, join. The details that matter are formatting, padding, and edge cases.
Starting index: 1 is the most common (first line is line 1). Some contexts use 0 (common in array notation) or an arbitrary offset (for showing a snippet from line 150 of a file).
Padding width: if the line count is 100, line 5 should be shown as \"005\" (not \"5\") for visual alignment. Math.log10 of the final line number plus 1 gives the required width. The tool auto-computes this or lets you set it manually.
Separator: the character(s) between number and line content. Common choices: \":\" (colon), \" \" (space), \" | \" (padded pipe), \"\\t\" (tab), \". \" (period-space for legal numbering). The separator is configurable.
Skip blank lines: some conventions number only content lines (useful for code excerpts); others number every line (useful for file reference). The tool offers both.
Skip specific prefixes: you might want to not number comment lines (starting with // or #) or lines starting with whitespace. The tool offers a regex exclusion.
Renumbering an already-numbered text: re-running the tool on output would add another layer of numbers. The tool can detect existing line numbers (pattern: leading digits + separator) and strip them before renumbering.
Very large text: numbering is O(n) and fast. Multi-megabyte text numbers in under a second.
Line ending preservation: the output preserves whatever line ending the input used (Unix LF, Windows CRLF). Mixed inputs are normalized to match the majority.
Common problems and solutions
⚠Alignment broken by variable-width numbers
Line 1 and line 100 have different widths, making numbered output misaligned. Enable padding to zero-pad numbers to a consistent width.
⚠Existing numbers doubled
Running the tool on already-numbered text adds another layer. Enable the "strip existing numbers" option to detect and remove prior numbers first.
⚠Blank line handling assumption
Different conventions handle blanks differently: code line numbering usually skips blanks, legal text usually numbers blanks as empty numbered lines. Match your context.
⚠Starting index confusion
Is the first line 0 or 1? Programmers often start at 0 (matching array indexing); everyone else starts at 1. Match whatever tool will consume the output.
⚠Tab vs space separator
Tab separators align differently in different viewers because tab width varies. For consistent cross-tool display, use spaces or a pipe character instead of tab.
⚠Numbers break syntax in code
Numbered output is display-only, not executable code. Do not paste numbered code into a compiler — strip numbers first.
⚠Trailing newline edge case
If the input ends with a newline, the last line is empty. Do you number the empty line? The tool numbers it by default; disable if you want to skip trailing empties.
Add Line Numbers — comparisons and alternatives
Compared to Unix nl or awk, this tool has a visual preview and configurable separator without requiring command syntax. CLI tools win for scripted processing; this tool wins for interactive work.
Compared to text editor line number display (which is ephemeral, just a gutter), this tool embeds the numbers into the text itself for pasting elsewhere. Editors are for editing; this tool is for producing shareable numbered output.
Compared to Markdown numbered lists (1. item), this tool uses literal numbers that display in any viewer — Markdown list numbers are style-dependent and may render as bullets in some contexts.
Frequently asked questions about the Add Line Numbers
▶How do I add line numbers to text?
Paste your text, pick a starting number and separator, and the tool prepends numbers to every line. Default is 1-based with colon separator. Options let you zero-pad, skip blanks, or start from a different number.
▶Can I start numbering from a number other than 1?
Yes. Set the starting number to any integer — useful for showing a code snippet that really begins at line 150 of the full file. The first output line becomes "150:", the next "151:", and so on.
▶How do I get zero-padded line numbers?
Enable padding and either let the tool auto-compute width (based on final line number) or set a fixed width manually. Auto padding for a 50-line text gives "01, 02, ..., 50" with 2-digit width; auto for 500 lines gives "001, 002, ..., 500" with 3-digit width.
▶Can I skip blank lines from numbering?
Yes. Enable the skip-blank-lines option and only content lines receive numbers. Blank lines pass through unchanged. Useful for code snippet numbering where you only want to reference content lines.
▶What is the best separator?
Colon (":") is the most common convention for code and logs. Space or padded-pipe (" | ") works well for readability. Tab is convenient in editors that align tabs cleanly but breaks in others. Period (". ") suits legal and outline-style numbering.
▶How do I remove line numbers from already-numbered text?
This tool adds numbers; the companion operation is to strip them. Use a find-and-replace with regex: search for ^\\d+[:.]\\s* and replace with nothing. Or enable the "strip existing numbers before renumbering" option in this tool.
▶Is the input uploaded?
No. All processing runs in your browser. Your text — code, contracts, documents — never leaves your machine.
▶Does it work on very large text?
Yes. Numbering is a simple per-line operation that scales linearly. Multi-megabyte text numbers in under a second. The only practical limit is your browser’s ability to hold the string in memory.
Additional resources
- GNU nl manual — Unix nl command for line numbering in shell pipelines.
- Wikipedia — Line number — Historical background on line numbering conventions across programming and publishing.
- MDN String.prototype.split — JavaScript split method, used to break text into lines for numbering.
- RFC 5234 — ABNF — Augmented BNF, a formal grammar used for strict line-by-line protocol specifications where line numbering matters.
- Code formatting in Markdown — Markdown code block conventions including how line numbers are sometimes presented alongside code.
Related tools
All Text ToolsCase Converter
Convert between upper, lower, title, camel, snake, kebab, Pascal, CONSTANT cases
Find and Replace
Find and replace text with regex support, case sensitivity, whole-word matching, and preview of all changes before applying.
Line Counter
Count lines in text with separate totals for blank lines, non-blank lines, words, characters, and paragraphs for detailed statistics.
Remove Duplicate Lines
Remove duplicate lines from text with case-sensitive or case-insensitive matching, preserving original order or sorting the result.
Remove Line Breaks
Remove line breaks from text, convert to spaces, or keep paragraph breaks while flattening unwanted newlines.
Sort Lines
Sort text lines alphabetically, numerically, by length, randomly, or in reverse, with options for case sensitivity and duplicate removal.
Learn more
Explore more tools
200+ free tools that run in your browser.
Browse all tools →