Skip to main content

How to Add Line Numbers to Text or Code (and Number Lines the Way You Want)

A practical guide to adding line numbers to text or code: padding to align the column, choosing a start value and step, picking a separator, and processing everything locally.

Published By Li Lei
#text #line numbers #developer tools #productivity

How to Add Line Numbers to Text or Code (and Number Lines the Way You Want)

Numbering lines sounds trivial until you actually try to do it by hand. You type "1." in front of the first line, "2." in front of the next, and somewhere around line 30 you fat-finger a duplicate, or you reorder two items and have to renumber everything below them. For a fifteen-line checklist that is annoying. For a two-hundred-line log excerpt it is a waste of an afternoon.

A line-numbering tool removes the busywork. It prefixes each line with a sequential number, optionally padded so the numbers line up in a clean column, with a separator of your choosing between the number and the text, and a custom start value so the count can begin wherever you need. That last part is what turns it from a toy into something I reach for several times a week: numbering a list, quoting "line N" in a review, or generating an index column for a spreadsheet.

This guide walks through what each option does, when it matters, and a worked example you can copy.

What adding line numbers actually does

The core behavior is simple to state and easy to underestimate. Every line of your input gets a number stuck in front of it: 1, 2, 3, and so on down the block. The text of each line is copied through untouched, character for character, including leading spaces and punctuation. Nothing is rewritten — a number, a separator, and any padding are added to the front, and that is all.

Three knobs control the result:

  • Start at — the value of the first number. Leave it at 1 for a fresh list, or set it to 100 if you are numbering code that begins at line 100 of a real file.
  • Step — the increment between numbers. A step of 1 gives the familiar 1, 2, 3. A step of 5 gives 1, 6, 11, 16, which is handy when you want numbers that map to something else, like every fifth frame or every fifth measure.
  • Separator — what sits between the number and the line. A dot and a space ("1. ") reads like a normal list. A tab makes the number and the text land in two spreadsheet cells. A pipe ("1 | ") looks like a log gutter.

There is no "run" button to hunt for. The numbered output appears as you type, with a live line count, and a single click copies it to your clipboard.

Why padding matters: keeping the column straight

Once a list grows past nine items, the numbers start having different widths. Line 9 is one digit; line 10 is two. Left as-is, the text after each number jitters left and right as the digit count grows, and a long file becomes a ragged mess.

Turn on right-alignment and that goes away. The tool measures the largest number it will print and pads every number to that width — with zeros ("01") or with spaces, your choice. A 12-line list becomes 01, 02, … 12. A 1,280-line file becomes 0001 … 1280. The width is computed from the final number, so the column is exactly wide enough and never carries a stray extra space.

Zero-padding has a second, less obvious payoff. If you paste a numbered list into a spreadsheet that sorts text lexically, plain numbers go wrong fast: 1, 10, 2, 3 instead of 1, 2, 3, 10. Pad them — 001, 002, 010 — and lexical sort and numeric sort agree. For any ID column you intend to sort as text, padding is the difference between order and chaos.

A worked example

Say you have four onboarding steps written as plain lines:

Create your account
Verify your email address
Set up two-factor authentication
Invite your first teammate

Numbered with a dot-and-space separator starting at 1, you get:

1. Create your account
2. Verify your email address
3. Set up two-factor authentication
4. Invite your first teammate

Now suppose this block continues a section that ended at step 9. Set Start at to 10 and the same four lines come out as:

10. Create your account
11. Verify your email address
12. Set up two-factor authentication
13. Invite your first teammate

Switch the separator to a tab and turn on zero-padding, and each row becomes "10⇥Create your account" — a number cell and a text cell, ready to paste straight into two spreadsheet columns. No retyping, and reordering a line then re-running is instant.

Common uses: reviews, lists, and paginated output

The option set maps onto a handful of jobs that come up over and over.

Referencing exact lines in a review. To tell a teammate where a problem is, "line 42 of this snippet" beats "somewhere near the middle." Paste the snippet, number every line, set the start to the file's real first line number, and use a tab separator so it reads like an editor gutter. You and the reviewer now share a precise coordinate.

Numbering a checklist or a set of steps. Steps that live in a doc usually need numbers. Paste the plain lines, copy the numbered output, drop it back in. When a section continues an earlier one, the Start at value picks up exactly where the previous block ended.

Building an index column. A column of names or SKUs often needs a matching number column. A tab or pipe separator drops the number and the value into separate cells, and zero-padding keeps the IDs sortable.

Paginating or chunking output. When you need to walk through a long block in even pieces, a step value lets you number by tens or by hundreds so each chunk has a clear marker, instead of counting by hand.

There is also a reverse mode. Paste an already-numbered list and the tool strips the leading prefix — "12. ", "007 | ", "3)", "5:", or a tab-separated number — off each line and hands the clean text back. It is deliberately cautious: a line like "2024 budget", where a number is glued to a word with no separator, is left untouched, so it won't eat real content. Add-then-remove is a clean round trip, which makes it safe to number a snippet for review and then strip it back before you commit.

How I use it, and one caveat

I keep this open in a tab whenever I am writing release notes. My usual flow is to dump a rough list of changes, number them, reorder a few, and re-run — the renumbering is automatic, so I never end up with a "7, 8, 8, 9" off-by-one that I have to chase down later. The trick I rely on most is Start at: our notes are split across sections, and being able to continue numbering from where the last section stopped saves me from a manual renumber every single time. When I am quoting a config file in a bug report, the tab separator plus a real starting line number makes the paste look like it came straight out of the editor.

One thing worth knowing: blank lines. By default an empty line still gets a number, so a paragraph break becomes "3. " with nothing after it. Tick "Skip blank lines" and empty rows are left exactly as they are while the counter holds its place — so a gap between item 2 and item 3 stays a gap, and the next real line is still numbered 3. That keeps the visible count contiguous across spacing.

Because all of this is plain JavaScript running in your browser tab, the text you paste never leaves the page. You can number private notes, internal code, or unreleased copy without it being uploaded or logged. (The only exception is the shareable URL, which encodes your text in the link — for anything sensitive, use the copy button instead of sharing the address.)

When you are done numbering, the cleaned-up list often wants one more pass — and that is where the rest of the toolbox comes in. Run Add Line Numbers to number or strip your lines, then send the result through Text Sorter if you need it in a different order before the numbers go on. Number, sort, renumber: three quick steps, zero manual counting.


Made by Toolora · Updated 2026-06-13