JavaScript Escape / Unescape
This JavaScript escaper converts text into the body of a string literal: your chosen quote character is escaped so the literal does not end early, backslashes are doubled, line breaks become \n, tabs become \t, and remaining control characters become \uXXXX escapes. The output deliberately has no surrounding quotes, because you are almost always pasting into quote marks that already exist in your source. Unescaping reverses the process, including \uXXXX, \u{...} and \xXX forms. Everything runs in your browser.
How it works
Escapes what would otherwise end or corrupt a JavaScript string literal: the quote character you are using, backslashes, line breaks, tabs and control characters.
The result is the body of a literal, without the surrounding quotes, so you can paste it between quote marks you already have in your source.
Escaping runs entirely in your browser — nothing you paste is sent to a server.
0 characters in · 0 characters out
How to escape a JavaScript string
- Paste your text into the input on the left.
- Pick whether the literal you are pasting into uses double or single quotes.
- Copy the escaped body and paste it between your existing quote marks.
What gets escaped
- The quote character you selected, so the literal does not end early.
- Backslashes, which would otherwise start an escape sequence of their own.
- Line breaks as
\n, carriage returns as\r, tabs as\t. - Remaining control characters as
\uXXXX.
The output has no surrounding quotes
What you get back is the body of a literal, not a complete one. That is deliberate: you are almost always pasting into quote marks that already exist in your source, and a second pair would have to be deleted every time.
Common use cases
- Embedding a block of prose, HTML or JSON in a string constant.
- Putting multi-line text into a single-line literal.
- Reading an escaped string out of a minified bundle to see what it says.
Frequently asked questions
What does escaping a JavaScript string do?
It replaces the characters that would end or corrupt a string literal — your quote character, backslashes, line breaks, tabs and control characters — with escape sequences, so the text can live inside quotes safely.
Why is the output missing its quotes?
Because you are usually pasting into quote marks that already exist in your code. Returning a complete literal would mean deleting a second pair every time.
Does it matter whether I use single or double quotes?
Yes. Only the quote character you actually use needs escaping, so choose the matching style and the other quote is left readable rather than cluttered with backslashes.
Which escape sequences can it decode?
The named ones such as \n, \r, \t, \b, \f and \v, plus \xXX byte escapes, \uXXXX code units and \u{...} code points.
Is my text sent to a server?
No. Escaping happens entirely in your browser.
Related tools
Java Escape / Unescape
This Java escaper handles the sequences Java accepts, including ASCII-only output for properties files.
C# / .NET Escape / Unescape
This C# escaper prepares text for a regular string literal, with a note on verbatim strings.
JSON Stringify & Escape
This JSON stringify tool escapes a document into a string literal you can embed, and unescapes it again.