String Escaper & Unescaper

Escape and unescape strings for HTML, JavaScript, JSON, Python, SQL, RegExp, and CSV — free, instant, runs entirely in your browser. Supports auto-detection and roundtrip verification.

Special Characters Reference
Char Name HTML JS / JSON Unicode

Did we solve your problem today?

What is String Escaping?

String escaping replaces special characters with safe sequences that can appear in contexts where the raw character would otherwise cause syntax errors, security issues, or data corruption. Every programming language and data format has its own escape rules — using the wrong ones (or forgetting them entirely) is a common source of bugs, injection vulnerabilities, and broken output.

This tool supports seven formats: HTML, JavaScript, JSON, Python, SQL, Regular Expressions, and CSV.

HTML Escaping

HTML reserves five characters that must be escaped inside element content and attribute values:

Raw characterEscaped form
&&
<&lt;
>&gt;
"&quot;
'&#39;

Forgetting to escape user-supplied text before embedding it in HTML is the root cause of Cross-Site Scripting (XSS). Always escape at the point of output, not at the point of input.

JavaScript String Escaping

Inside a JavaScript string literal, the backslash \ acts as an escape prefix:

SequenceCharacter
\\Backslash
\"Double quote
\'Single quote
\nNewline (LF, U+000A)
\rCarriage return (U+000D)
\tHorizontal tab (U+0009)
\0Null character (U+0000)
\bBackspace (U+0008)
\fForm feed (U+000C)
\vVertical tab (U+000B)
\uXXXXUnicode code point

JSON String Escaping

JSON is stricter than JavaScript: only double-quoted strings are valid, and only a specific set of escape sequences is permitted by RFC 8259. Control characters (U+0000–U+001F) that are not handled by a named sequence must be encoded as \uXXXX.

Python String Escaping

Python uses the same backslash convention as JavaScript with one addition: \a represents the bell/alert character (U+0007, \x07). Python’s raw strings (r"...") disable escape processing — useful when writing regular expressions.

SQL Escaping

SQL uses a different convention: a single quote inside a string literal is escaped by doubling it (''), not by a backslash. Some database engines (notably MySQL with default settings) also treat \\ as an escaped backslash. Always use parameterised queries instead of manual string escaping in production code — SQL escaping by hand is error-prone.

Regular Expression Escaping

Regular expression engines assign special meaning to these metacharacters:

. * + ? ^ $ { } ( ) | [ ] \ -

If you want to match any of these literally, prefix them with a backslash. For example, to match a literal dot use \. rather than . (which matches any character). This tool escapes all metacharacters to produce a safe literal pattern.

CSV Escaping (RFC 4180)

CSV has no universal standard, but RFC 4180 is widely adopted. The rules are:

A field without special characters requires no quoting and is left unchanged.

Roundtrip Safety

Every escape type in this tool is designed to be fully reversible: escaping a string and then unescaping the result always returns the original input. You can verify this with the Escape → copy output → paste as input → Unescape workflow.

FAQ

What is string escaping?

String escaping replaces special characters with safe equivalents so they can appear in contexts where they would otherwise cause syntax errors or security issues. For example, a double quote inside a JavaScript string literal must be escaped as \" to avoid ending the string prematurely.

What escape types are supported?

This tool supports seven formats: HTML (& < > " '), JavaScript (\n \t \" etc.), JSON (same as JS but stricter), Python (adds \a for the bell character), SQL (single-quote doubling and backslash escaping), Regular Expressions (metacharacter escaping), and CSV (RFC 4180 quoting).

What is the difference between JavaScript and JSON escaping?

JavaScript escaping handles a wider range of sequences including single-quoted strings (\'). JSON escaping is stricter — only double-quoted strings are valid, and only specific escape sequences like \n, \r, \t, \b, \f, \", \\, and \uXXXX are allowed. This tool escapes control characters (U+0000–U+001F) as \uXXXX for JSON compliance.

Is my data sent to a server?

No. All escaping and unescaping runs locally in your browser using pure JavaScript string operations. Your data never leaves your device and is not stored anywhere. The tool works offline once the page has loaded.

What does the auto-detect feature do?

Auto-detect analyses your input text and selects the most likely escape type based on patterns: HTML entities (&amp;, &lt;), doubled SQL quotes (''), regex metacharacter escapes (\. \*), and JS escape sequences (\n \t). It is a heuristic — for ambiguous input, select the type manually.