FormatterHQ

CSV Escape

Escape a value so it can be used as a single CSV field. Adds surrounding quotes only when needed and doubles embedded quotes, following RFC 4180.

Loading tool…
Ready.

How to use the CSV Escape

  1. Type or paste into the Raw text box, or click Sample. You can also drop a text file on either box, or load one into the Escaped CSV box with its Open file button.
  2. The Escaped CSV box updates live as you type. It works both ways — edit the Escaped CSV side to convert back, or click ⇄ Swap to exchange the sides.
  3. Adjust Delimiter in the options bar above the editors; the result refreshes immediately.
  4. Use Copy or Download on either box to take the result, or Clear to start again.

CSV escape rules (RFC 4180)

CSV looks simple until a value contains the delimiter, a quote or a line break. A CSV escape wraps such a field in double quotes and doubles every quote inside it, so that spreadsheet programs and CSV parsers read it back as one value. This tool applies those rules to whatever you paste.

A field is quoted when it contains any of the following:

  • The selected delimiter (comma, semicolon, tab or pipe).
  • A double quote — each " inside the value becomes "".
  • A line feed or carriage return, so multi-line values stay in one field.
  • Leading or trailing whitespace, which some parsers would otherwise trim.

Values without any of these are returned unchanged, which keeps files small and readable.

Example

Input:

Widget, large "XL" edition

Output:

"Widget, large ""XL"" edition"

With the Semicolon delimiter, common in European versions of Excel, a;b becomes "a;b" while a comma no longer triggers quoting.

Why the delimiter option matters

Quoting depends on which character separates the columns. A value with a comma must be quoted in a comma-separated file, but is harmless in a tab-separated one. Pick the delimiter of the file you are editing so only the necessary fields get quoted.

Quoting also protects values that contain the delimiter by accident, such as prices with a decimal comma (“3,50”) in a comma-separated file, or pipe characters inside free-text notes in a pipe-delimited export.

This “quote only when needed” behaviour matches Python’s csv.writer with its default QUOTE_MINIMAL setting and what Excel and Google Sheets write when they export. Some tools quote every field instead; both styles are valid and read back identically.

What CSV escaping does not cover

Escaping keeps the file structure intact, but it does not stop spreadsheet programs from interpreting a value. A field that starts with =, +, - or @ may be treated as a formula when the file is opened in Excel or similar apps (known as CSV or formula injection). If you export user-supplied data, prefix such values with a single quote or a space according to your application’s policy.

To build a full CSV file from structured data, try JSON to CSV, and use CSV Unescape to reverse a single field. Everything runs in your browser.

Frequently asked questions

How do you escape a double quote in CSV?
Double it. The value 5" screen becomes "5"" screen" — the whole field is wrapped in quotes and the inner quote is written twice. Backslash escaping is not part of standard CSV.
How do I include a comma in a CSV field?
Wrap the field in double quotes: "London, UK". Parsers then treat the comma as part of the value instead of a column separator.
Can a CSV field contain line breaks?
Yes, as long as the field is quoted. Excel, Google Sheets and RFC 4180 parsers keep the line break inside the cell.
Does this protect against CSV formula injection?
No. Quoting preserves the structure of the file but does not stop spreadsheet apps from evaluating values that begin with =, +, - or @. Handle those separately when exporting untrusted data.

Last updated October 3, 2026

Related tools