Skip to content
CertoflowCertoflow
Developer Tools

Add Line Numbers to Text — Free Tool

Number lines in text.

Last updated: August 2026

Quick reference

What this calculator does
Prefix each line with padded line numbers — 4-digit width and pipe separator for code review, logs, and documentation.
How it works
Paste multiline text; each line receives a right-padded line number followed by | and the original content.
Example
Two lines become ' 1 | first' and ' 2 | second' with four-character number field.
When to use it
Code review comments, bug reports citing line ranges, and formatting log excerpts for email or chat.

Guide

Introduction

"See line 847" means nothing if the recipient cannot find line 847. Pasting code or logs into Slack, GitHub issues, or email loses editor line numbers unless you add them manually — error-prone for multi-hundred-line snippets. cat -n and nl exist on Unix; Windows developers and browser-only workflows need a paste tool.

Certoflow's Line Number Generator splits input on newlines, prefixes each with a four-space-padded number and | separator, and preserves original line content including empty lines. Live output. Local processing. Use with Strip HTML Tags when numbering extracted text, JSON Formatter before numbering formatted JSON for review threads, and diff tools externally for comparing numbered versions.

What this tool does

FeatureBehavior
InputArbitrary multiline text
Number format4-digit right-padded ( 1, 42, 1234)
SeparatorSpace-pipe-space (|)
Empty linesStill numbered
CopyCopy numbered output

Line numbers start at 1. No configuration for start offset, delimiter style, or tab alignment.

How it works

export function addLineNumbers(text: string): string {
  return text
    .split("\n")
    .map((line, i) => `${String(i + 1).padStart(4, " ")} | ${line}`)
    .join("\n");
}

Trailing newline in input creates final empty numbered line if input ends with \n — standard split behavior.

Real-world examples

GitHub issue stack traces

Paste stack trace, add line numbers, reference lines 12–15 in issue description for maintainers.

Code review in chat

Slack code blocks lack native line numbers — prepend here before triple-backtick paste.

Log excerpt for postmortem

Number log lines when correlating with metrics timestamps in incident documents.

Teaching programming

Instructors number student submissions for classroom discussion without returning graded files.

Pairing with XML or JSON

Format with XML Formatter or JSON Formatter first, then number for specification review meetings.

Common mistakes

Assuming numbers match production file lines. Offsets change if you paste partial snippets — note starting context in comments.

Four-digit overflow. Line 10000 displays as 10000 without padding shrink — padStart minimum width four, longer numbers expand.

Numbering then editing. Regenerate after content changes or line references drift.

Expecting gutter alignment across fonts. Proportional fonts misalign — use monospace in destination viewer.

Including line numbers in executable code. Strip numbers before running — output is for human reference only.

Windows CRLF handling. \r may appear at line ends if pasting Windows text — trim carriage returns upstream if needed.

Use cases

Developers citing lines in async code review.

SRE staff documenting log correlations.

Educators referencing student code in feedback.

QA engineers bug reports with precise reproduction lines.

Technical writers tutorial errata pointing to specific lines.

Support engineers escalating issues with numbered excerpts.

FAQ

Starting line number?

Always 1.

Custom separator?

Fixed | — edit output manually if needed.

More than 9999 lines?

Numbers grow beyond four characters naturally.

Empty input?

No output until text provided.

Preserves trailing spaces on lines?

Yes, after separator.

Tab characters?

Preserved in line content.

Offline?

Yes.

Reverse operation?

Not supported — remove numbers manually or with regex.

Related?

JSON Formatter, XML Formatter before numbering.

Uploaded?

No. Local only.

Workflow with diffs and reviews

Numbered excerpts integrate best with monospace fonts in GitHub, GitLab, and Slack code blocks. Paste numbered output inside fenced blocks so proportional fonts do not misalign the gutter. When referencing lines across versions, include the commit hash or file path in prose alongside line numbers — numbers alone lose meaning after the source file changes. For JSON or XML reviews, format first with JSON Formatter or XML Formatter so logical line breaks align with structural boundaries, then number — reviewers spot missing commas faster when each property occupies its own numbered line. Automated tools cannot consume this output directly; strip the numeric prefix with a regex like ^\s*\d+\s\|\s if you need to recover original content for compilation after review cycles conclude.

Accessibility and screen readers

When sharing numbered excerpts with colleagues using screen readers, remember that prefixed numbers are read aloud before each line content — sometimes confusing for long lists. For public documentation, consider whether line numbers help or hinder accessibility; alternative approaches include linking directly to repository line anchors on GitHub rather than pasting static numbered blocks that go stale. For internal debugging during live incidents, numbered logs remain invaluable because incident commanders reference exact lines in bridge calls without waiting for everyone to open the same editor version.

Frequently Asked Questions

Is data uploaded?
No. All processing runs locally in your browser.
Does this work offline?
Yes, after the page loads.

Related tools that complement this workflow.