My Tool Studio
Text

Add Line Numbers to Text

Paste code, a log or a document and this tool will add line numbers to every line, so people can point to line 47 instead of quoting a whole paragraph. Pick a format: 1 | text aligned, 1. text, 1) text, [1] text, 01. text, 1: text, a number and a tab, Line 1: text, or your own text before and after the number. Start at any number, count in steps such as 10, 20, 30, pad with zeros or spaces, skip blank lines, or put the number at the end of each line. A Remove numbers mode does the reverse and strips line numbers from code copied out of a tutorial or a PDF. Developers use it for bug reports and code reviews. It runs in your browser.

Always freeNo sign upRuns in your browser

How to use

01

Paste your text

Paste code, logs or a document into the Text to number box. Press Try sample to load a short JavaScript snippet with a blank line in it.

02

Pick a format and start number

With Add numbers selected, choose a Format, set Start at and Step, pick a Padding and whether to Put the number at the start or end, and tick Skip blank lines if needed.

03

Copy, or remove numbers instead

Press Copy on the Numbered text pane. To strip existing numbers from pasted code, click Remove numbers and paste the numbered text; the counter shows how many lines changed.

Why Add Line Numbers to Text

Line number format examples

Each format applied to two lines, a and b, with Start at set to 9 so the padding is visible when the count reaches two digits. Pick the one your destination expects: aligned formats for code in a monospace font, dotted formats for documents, and the tab format for pasting into a spreadsheet, where the number and the text land in separate columns.

FormatLine 9Line 10
1 | text (aligned) 9 | a10 | b
1. text9. a10. b
1) text9) a10) b
[1] text[9] a[10] b
01. text (leading zeros)09. a10. b
1: text9: a10: b
1 then a tab9(tab)a10(tab)b
Line 1: textLine 9: aLine 10: b
Custom, # before and a space after#9 a#10 b

Common questions

What line number formats can I add to text?
There are nine: 1 | text, 1. text, 1) text, [1] text, 01. text, 1: text, a number followed by a tab, Line 1: text, and Custom, where you type the text that goes before and after the number, such as # and a space for #1 text. The 1 | text format pads numbers with spaces so the separators line up, and 01. pads with zeros.
Can I start line numbering at 0 or another number?
Yes. Type the first number in the Start at field, which lets you match the real line numbers of an excerpt from a longer file. Counting goes up by one per line, or by the amount in Step, so a step of 10 gives 10, 20, 30 like old BASIC listings.
How do I remove line numbers from copied code?
Click Remove numbers and paste the text. The tool strips a number at the start of each line when it is followed by a separator such as a dot, a bracket, a colon, a pipe or a tab. The counter tells you how many lines were changed.
Will Remove numbers delete numbers that are part of my text?
It only removes a number at the very start of a line that is followed by one of the separators it knows. A line like 2024 was a good year is left alone, and so are times like 10:30 and decimals like 3.5. A line such as 1. Preheat the oven in a numbered recipe will lose its number, since that looks exactly like a line number.
Do blank lines get line numbers too?
By default, yes, every line is numbered, including empty ones. That keeps the numbers in step with what a code editor shows, so a reviewer who says line 12 means the same line you see. Tick Skip blank lines to leave empty lines unnumbered; the count then continues on the next line with text.
Why are the numbers padded with spaces in the 1 | text format?
Padding keeps the pipe separators in a straight column when the text is shown in a monospace font. The width follows the largest number, so a 250-line paste pads every number to three characters.
Can I put the line number at the end of each line instead?
Yes. Set Put the number to At the end of the line. The text comes first and the number follows it with a space, for example Buy milk [1] with the bracket format, or after a tab with the tab format. It is useful for numbering answers or references without shifting the start of each line.
Which line number format works for a Word or Google Docs document?
1. text and 1) text read naturally in documents. Be aware that Word and Google Docs may turn a line you type that starts with 1. into an automatic numbered list, which you can undo with Ctrl+Z. The tab format lines up neatly in documents with default tab stops.
Does adding line numbers change my original text?
No. Your input stays as you pasted it, and the numbers only appear in the output. Keep the unnumbered version for anything that goes back into an editor or a build.

More Text tools

View all