Skip to content

Add Line Numbers

Add line numbers to text online with custom starting number and formatting options. Free line numbering tool for code and documents.

Text Tools
Instant results
Output will appear here...

About Add Line Numbers

Add line numbers to any text or code. Customize the separator, starting number, and padding. Useful for code reviews, documentation, and referencing specific lines.

How to Use Add Line Numbers

1

Paste your text

Drop in the text or code you want numbered. Every line will receive a number prefix in the output.

2

Configure format

Pick a separator (pipe, colon, period, or plain space), set the starting number (1 by default), and choose padding behavior — auto-detected from the line count or set manually. Tweak each option to match your style guide.

3

Preview output

The numbered version appears immediately so you can confirm alignment, check that the separator reads well, and iterate on format choices before committing.

4

Copy result

Send the final output to your clipboard with one click. Paste into documentation, blog posts, emails, or code review threads where having stable line references makes the conversation easier.

When to Use Add Line Numbers

Code documentation

Tutorials, blog posts, and technical docs benefit enormously from numbered code snippets — readers can scan a paragraph that says 'on line 12 we initialize the array' and immediately find the relevant spot. Adding numbers in advance saves the reader from counting and gives the writer a stable anchor for explanations.

Code review references

Discussing code over email, Slack, or in a Google Doc gets confusing fast without something to point at. Numbered lines turn 'this part is broken' into 'line 47 is broken' and make asynchronous review actually work, especially when the reviewer can't pop open the same IDE.

Educational materials

Programming exercises and worked examples land much harder when students can follow along by line number. Workbooks, online course handouts, and classroom slides all gain clarity once each step has a precise reference attached.

Log file analysis

Plain log files don't come with line numbers, which makes pointing teammates at a specific event awkward. Numbering the relevant chunk first turns 'somewhere in the middle, the auth call failed' into 'line 218 shows the failed auth call' — far easier to discuss and share.

Add Line Numbers Examples

Standard format

Input
Three lines of code without numbers
Output
1| function hello() {\n2|   console.log('Hi');\n3| }

The basic numbering pattern is number plus separator plus content. The pipe character is the most common separator in technical writing, though some prefer a colon or simply extra space. Padding handles alignment when line counts grow into the hundreds.

Custom format

Input
10 lines of code
Output
Several output styles such as '1: ', '01: ', '1. ', and '1 | ' to match your style guide.

Different contexts call for different separators. Markdown blogs often work well with '1: ', formal technical docs use '1. ', and minimalist formats stick with '1 |'. The right choice depends on where the snippet will eventually be rendered.

Starting from a custom number

Input
Add numbers beginning at 100
Output
100: line a\n101: line b\n102: line c

Custom starting numbers help when the snippet continues from an earlier section, references lines deep inside a much larger file, or highlights a specific block while preserving its real-file line numbering.

Tips & Best Practices for Add Line Numbers

  • 1.Right-align the numbers when files run into three or four digits. A right-aligned ' 1' lines up cleanly with '100', while a left-aligned '1' produces a ragged left edge that reads badly.
  • 2.Pad numbers to the expected maximum width. A file of several hundred lines reads better with '001' style padding because every line begins at the same column.
  • 3.Pick a separator that suits the surrounding context. Pipes feel technical and explicit, colons stay compact, periods read like a list, and a single space works when you want minimal visual noise.
  • 4.Start from one by convention, since that's what most code editors display. Academic contexts and zero-indexed languages occasionally start from zero, but make the choice deliberate.
  • 5.Don't try to number five thousand lines in a single block. Break long code into sections, restart numbering at logical points, or paginate so readers aren't drowning in digits.
  • 6.Markdown code blocks can produce numbered lines through highlight.js or the Prism.js line-numbers plugin. Reach for this tool when those plugins aren't available or when you need plain-text output you can paste anywhere.

Frequently Asked Questions

It prepends a line number to every line in your input, with options for the starting number, the separator character (typically pipe, colon, or period), the padding strategy, and the overall format. Common destinations include code documentation, async code reviews, log analysis, and educational materials where exact line references matter.