Adding a prefix to each line means placing a fixed string of text at the beginning of every input line while preserving the original line content and the order of those lines. The prefix is concatenated directly to the front of each line, the suffix (if any) is concatenated to the end, and nothing in between is changed, removed, re-cased, sorted, or deduplicated. Spaces, tabs, and any internal whitespace inside each line are kept exactly where they were. The output is the original line list, decorated with the literal characters you typed. The prefix and suffix are treated as plain strings rather than templates: brackets, quotes, dollar signs, backslashes, asterisks, and parentheses are inserted exactly as written, with no interpretation as regular expressions, replacement tokens, Markdown, HTML, or code. Each prefix and suffix is limited to 200 Unicode characters, and at least one must be non-empty, because producing an unchanged duplicate would add no value and could confuse the current result with the input. Up to one million input characters are accepted, line order is preserved, and every logical line is processed once in the order it appears.

Because the prefix and suffix are literal, the operation is predictable in a way that a regex engine or a template engine would not be. The next sections explain what the transformation does to your text, where it is genuinely useful, how to run it with the Add Prefix and Suffix to Lines tool, and how the blank-line, line-ending, and preview behaviors actually behave.

add prefix to each line explained
add prefix to each line explained

What the Operation Actually Does to Your Text

For each logical line in your input, the transformation produces a single output line that is exactly prefix + original line + suffix. The original line content is never trimmed at either end, never collapsed, never re-cased, never sorted, and never deduplicated. If your input has ten lines, the output has ten lines, or eleven if a trailing newline creates one extra empty logical line. The operation does not remove blank lines, although the blank-line option changes whether those blanks receive the prefix and suffix.

A short worked example makes the mechanics concrete. Suppose the input contains three lines: apple, banana, cherry. With a prefix of - and no suffix, the output is exactly three lines: - apple, - banana, - cherry. Line order is preserved, the original words are unchanged, and the literal hyphen-and-space appears at the start of every line. Adding a suffix of ; produces - apple;, - banana;, - cherry;. Nothing inside the original line is rearranged, only prepended or appended.

The key behavioral detail is that the prefix and suffix are plain character strings. Brackets, dollar signs, parentheses, and backslashes are inserted verbatim because no part of the operation interprets them. The MDN documentation for String trim confirms that JavaScript treats them as ordinary characters, which is the model the Add Prefix and Suffix to Lines tool follows. A tool that interpreted the prefix as a regex would let $1 silently expand to a captured group, while a template engine would let {{var}} try to resolve a variable that does not exist. Literal-only behavior sidesteps both problems.

Where Adding a Prefix (or Suffix) to Each Line Helps

The operation shows up whenever a line list needs the same wrapper text on every entry. It is the right tool when the work is purely mechanical, identical on every line, and free of conditional logic.

ScenarioTypical prefixTypical suffixWhy literal text matters
Markdown bullets- or * (none)The asterisk must remain literal, not act as a regex wildcard.
Shell or config comments# (none)The hash must stay a literal character, not a comment marker inside a template engine.
SQL IN clause values''Single quotes must not be treated as opening string delimiters by a downstream parser.
Log line tags[INFO] (none)Square brackets and the closing bracket must appear exactly as typed.
JSON-style array values""Double quotes must remain literal characters, not regex metacharacters.
YAML list items- (none)Hyphen and space are literal, not a range operator.
Closing punctuation(none);Semicolons stay literal, so shell or SQL parsers receive the exact character.

In each of these cases, the prefix or suffix is something you would otherwise type by hand on every line. Doing it by hand is tedious for ten lines and error-prone for a thousand. A literal, in-browser tool removes the typing without introducing the unpredictable behavior of a regex engine or a templating system. The tool that does this directly is Add Prefix and Suffix to Lines.

How to Add a Prefix to Each Line

  1. Paste or type the lines you want to decorate into the input area. Up to one million characters are accepted, including all line breaks.
  2. Enter a prefix, a suffix, or both in their respective fields. Each affix is limited to 200 Unicode characters, and at least one must be non-empty.
  3. Choose whether blank lines should remain unchanged or also receive the prefix and suffix. The choice changes coverage but never deletes a line.
  4. Generate the result. The transformed text appears in a preformatted preview that preserves spaces and newlines while allowing long visual wrapping.
  5. Download the result as a UTF-8 TXT file when you are satisfied with the preview. The file uses LF line endings and contains only the generated string.

That sequence mirrors the verified contract of the tool: paste, configure affixes, choose a blank-line policy, generate, inspect the preview, and download. Editing any of the inputs, affixes, or settings after generating clears the previous result and revokes the old download URL, so you cannot accidentally keep an outdated file linked to a newer configuration.

The Blank-Line Option and Trailing Newlines

The blank-line setting controls how empty lines and whitespace-only lines are handled. With the option to leave blank lines unchanged enabled, an empty line and a line that contains only spaces or only tabs are returned exactly as they were. The whitespace inside a whitespace-only line is not stripped, so the MDN String trim behavior is intentionally not applied. With the option disabled, every logical line is decorated, including empty lines and lines that contain only whitespace. Either way, no line is removed from the output.

A subtle point worth flagging: a trailing newline in the input creates a final empty logical line. When blank lines are decorated, that final empty line receives the prefix and suffix as well, which can produce a trailing decorated line in the output. When blank lines are skipped, the final empty line remains empty. The behavior is deliberate so that the last boundary represented by your input is not silently lost in the downloaded file.

Line Endings, Preview, and the Downloaded File

The input area recognizes all three common line-break conventions: Windows CRLF, classic Mac CR, and Unix LF. The generated output normalizes whichever mix you pasted to a consistent LF. If you copy text from a Windows source, paste it, generate the result, and download the file, the saved file uses LF throughout, which is what most downstream Unix tools and most editors expect.

The preview is a preformatted region that shows the exact string that will be downloaded. Visual line wrapping inside the preview is a display feature only: it does not insert a real newline into the file. The downloadable file itself is a UTF-8 plain-text Blob, with no byte-order mark, no rich-text styling, no spreadsheet quoting, no CSV escaping, and no filename-derived prefix. The download contains only what the transformation produced, so what you see in the preview is exactly what you get in the file.

Editing the input, prefix, suffix, or blank-line setting after a download clears the previous result and revokes the old download URL. That is a deliberate safeguard against leaving a stale file reachable while the controls describe different output.

When a Different Tool Is the Better Fit

Adding a prefix to each line is a narrow operation, and several related tasks look similar but are not covered. If you need sequential numbers on every line, in the form 1., 2., 3., and so on, use a tool that prepends numbers rather than literal text. If you need to change a substring that already exists inside the lines, use a literal find-and-replace tool, which handles matching and case sensitivity without the surprises of a regex engine. If you need CSV, JSON, or SQL IN-clause quoting with proper escaping for those formats, use a quoting-specific tool, because each of those formats has its own escaping rules that a plain prefix-and-suffix operation does not apply. The Add Prefix and Suffix to Lines tool is intentionally narrow: it concatenates two literal strings onto each line and joins the result with LF, nothing more. For a printable companion that lists the most common patterns (bullets, comments, quotes, indentation, closing punctuation) in one place, see the Add a Prefix to Each Line: Cheat Sheet of Patterns guide.