Overview
Introduction
Adding line numbers by hand to reference specific lines in a code review, discussion, or tutorial is a tedious, error-prone edit to make across more than a few lines.
It runs entirely client-side, so nothing you paste is ever uploaded to a server.
What Is Line Number Adder?
A line-numbering tool that prefixes every line of your text with its 1-based line number and a separator you choose, like '. ', ': ', or ') '.
It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.
How Line Number Adder Works
The tool splits the input on newline characters, prepends each line with its index plus one and the chosen separator, and joins the lines back together with newlines.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use Line Number Adder
Use it to number a list for reference in a discussion, prepare a code snippet with visible line numbers for a tutorial, or create an ad-hoc numbered outline.
It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.
Often used alongside Line Number Remover and Line Counter.
Features
Advantages
- Separator is fully configurable, supporting '.', ':', ')' or any custom marker.
- Numbers every line consistently, including blank ones, with no manual counting required.
- Splits on the newline character alone, so a document with Windows line endings keeps its carriage returns while still receiving exactly one number per line.
Limitations
- Always starts numbering at 1 with no option to start from a different number.
- Adds a plain text prefix; it doesn't produce an HTML ordered list or editor-style gutter numbering.
Examples
Best Practices & Notes
Best Practices
- Use Line Number Remover afterward if you need to strip the numbers back out later, such as before re-processing the raw list.
- Pad the numbers first with the String Left Padder when the text after them needs to align, since single- and double-digit numbers differ in width.
- Number only once editing is finished, because inserting a line afterwards means renumbering the entire block.
Developer Notes
The implementation is `input.split("\n").map((line, index) => `${index + 1}${separator}${line}`).join("\n")`, a straightforward per-line map using the array index (zero-based) shifted by one to produce 1-based line numbers.
Line Number Adder Use Cases
- Numbering lines for reference in a code review or discussion
- Preparing a code snippet with visible line numbers for a tutorial
- Creating a quick numbered outline from a plain list
Common Mistakes
- Expecting numbering to start at 0 instead of 1.
- Forgetting to include a separator, which runs the number directly into the line content.
Tips
- Use a separator like ') ' to mimic a classic outline style, or ': ' when the numbers represent references rather than a sequence.
- Blank lines are numbered too, which is exactly what keeps the numbering aligned with an editor's own line numbers for a code snippet.