String Escape And Unescape
For Code, SQL And HTML
This string escape tool turns text into safe code strings and back again. Pick a format, paste your text, and copy the result. We upload nothing.
- FreePrice
- 13Formats
- NoneSign-up
- NoneUploads
String Escape And Unescape
Escape or unescape text for code, markup, SQL, CSV and URLs
- Lines
- 0
- Characters
- 0
- Change
- 0
Ready. Pick a format and paste your text.
What A String Escape Tool Does For You
Some characters carry a special meaning in code. A quote ends a string. A backslash starts an escape. An ampersand starts an entity. So one stray character can break a whole line.
A string escape tool fixes that. First, you paste your text. Then you pick a format such as JavaScript, SQL or HTML. The safe version appears as you type, and you copy it with one click.
Also, it works both ways. Escape turns raw text into a safe string. Unescape turns a safe string back into text you can read. So you can check what a log line or an old string really says.
Everything runs in your browser. So your text never leaves your device. That matters, because the strings you handle may hold queries, keys and private data.
Escape And Unescape HTML
HTML treats the less than sign and the ampersand as markup. So you must escape them before you show code on a page. The tool turns the ampersand into &, the less than sign into < and the greater than sign into >. It also handles both kinds of quote.
Next, you can turn letters such as é into numeric entities like é. Also, you can turn line breaks into br tags. Then you paste the result straight into a page.
For more detail, see: MDN guide to JavaScript grammar and types.
Escape And Unescape XML
XML is stricter than HTML. It knows five entities: &, <, >, " and '. So the tool uses ' for the single quote, where HTML uses a number.
Then unescape reads those entities back, and numeric ones too. Also, the line break option turns a new line into , which keeps a line break inside an attribute.
Escape A JavaScript String
JavaScript strings use a backslash for special characters. So a new line becomes \n, a tab becomes \t and a backslash becomes two. First, you choose double quotes, single quotes or backticks. Then only the quote you picked gets a backslash.

Also, a backtick string keeps ${ safe, so a template literal does not run code by accident. Next, tick Escape non-ASCII characters to turn accented letters into Unicode escapes. Then the string works in any file encoding.
Escape A JSON String
JSON is stricter than JavaScript. It allows only double quotes, and it has no octal escapes. So the JSON option follows the JSON rules exactly.
First, it escapes quotes, backslashes and control characters. Then you paste the result between two double quotes, and the value is valid JSON.
Escape Strings For Java, C# And Python
Java, C# and Python share the same base. They use backslash n, backslash t and a backslash before a quote. However, each has its own details. Java has no vertical tab escape. C# has a bell escape. Python uses x for control characters and a capital U for characters beyond the basic plane.
So the tool follows each language, not one generic rule. Also, the Declare a variable option wraps the result in code. For example, it writes const text = "..."; for JavaScript and String text = "..."; for Java. Then you paste a ready line.
Escape A PHP String
PHP has two kinds of string. Single quotes know only two escapes, the backslash and the single quote. Double quotes also know \n, \t and \$.
So the quote style option picks the right rule. First, choose single quotes for plain text. Then choose double quotes when you need new lines or special characters.
Escape A SQL String
In standard SQL, you escape a single quote by doubling it. So O'Brien becomes O''Brien. However, MySQL also accepts a backslash. So tick MySQL backslash style to get a backslash before quotes, new lines and the rest.

Also, Wrap in quotes gives you the finished literal. Use it for quick fixes only. Then use parameters in real code, because a prepared statement is safer than any escape.
Escape A CSV Field
A CSV field needs quotes when it holds a comma, a quote or a line break. Inside the quotes, you double each quote. So the tool adds quotes only when they matter.
Also, tick Always quote the field to force them. Then unescape reads a quoted field back into plain text.
Add Slashes And Strip Slashes
The add slashes format works like the PHP function of the same name. It puts a backslash before a single quote, a double quote and a backslash. Then unescape removes those backslashes again.
Escape A URL
A URL allows only a small set of characters. So other characters become a percent sign and two hex digits. For example, a space becomes %20 and é becomes %C3%A9.
Also, tick Use a plus sign for spaces for form data. Then unescape reads either form back.
Escape A Regex
A regular expression treats dots, stars and brackets as commands. So to match them as plain text, you add a backslash. The Regex format does that for every special character.
Then you can paste a literal phrase into a pattern safely.
Unescape A String
Paste an escaped string and choose Unescape. First, the tool removes the quotes or the variable declaration if it finds one. Then it reads every escape and shows the plain text.
So you can read a string copied from a log, a database or a source file.
Check The Round Trip
Press Swap sides, and the result moves to the left box while the direction flips. So you can check a round trip in one click. If the text returns unchanged, the escape is sound.
Safe By Design
First, the tool works on plain text in your browser. It sends nothing, and it stores nothing. So your text stays yours.
On this page
- The tool
- What A String Escape Tool Does For You
- Using The String Escape Tool, Step By Step
- What This String Escape Tool Does Differently
- Habits For Escaping Strings Safely
- Common String Escape Mistakes This Tool Prevents
- String Escape Questions People Ask
- Handy Companions For Encoding Work
Keep going
Using The String Escape Tool, Step By Step
Four steps take you from raw text to a safe string.
- 1
Pick a format
Choose HTML, JavaScript, SQL or any of the thirteen formats.
- 2
Choose a direction
Escape raw text, or unescape a string you already have.
- 3
Paste your text
Paste it, open a file, or try the sample. The result appears as you type.
- 4
Copy or save
Copy the result, save it as a file, or swap sides to check it.
What This String Escape Tool Does Differently
It knows each language, it is private, and it works both ways.
Thirteen formats
HTML, XML, JavaScript, JSON, Java, C#, Python, PHP, SQL, CSV, slashes, URLs and regex.
Both directions
Escape and unescape with the same rules.
Language aware
Java, C# and Python each follow their own escapes.
Ready made variables
Wrap the result in a declaration for five languages.
Live result
See the result as you type.
Nothing leaves your tab
Your browser does the work. We never see your text.
Habits For Escaping Strings Safely
A few habits keep your strings sound.
- Pick the right format. A JavaScript escape differs from a Java escape. Choose the language you will paste into.
- Match the quote. Escape the same quote you will wrap the string in.
- Prefer parameters for SQL. Escaping helps with a quick fix, but a prepared statement is safer.
- Escape once. Escaping twice doubles every backslash.
- Unescape once too. Run it one time for each layer of escaping.
- Test the round trip. Use Swap sides to make sure the text comes back unchanged.
- Escape at output. Escape text when you write it into a page, not when you store it.
- Mind the encoding. Tick Escape non-ASCII characters when a file might lose accents.
- Keep secrets out. Do not paste live passwords or keys into any online tool.
- Check line breaks. Windows and Unix break lines in different ways, so look at the result.
- Read the result. Look at it once before you paste it into production code.
Common String Escape Mistakes This Tool Prevents
Each of these quietly breaks a line of code.
Double escaping
Escaping twice turns one backslash into four.
The wrong quote
A string with the wrong quote still breaks.
Bare ampersands
A lone ampersand can break a link or a feed.
SQL built by gluing
Joining text into a query invites injection. Use parameters.
Lost accents
Some files drop accents unless you escape them.
Regex dots
A dot with no backslash matches any character.
String Escape Questions People Ask
Is this string escape tool free?
Yes. It costs nothing, needs no account and has no limits. It runs in your browser, so we have no server cost to pass on.
Does my text leave my device?
No. Your browser does the converting. Nothing reaches this site, and we keep nothing.
What is string escaping?
It replaces characters that have a special meaning with a safe form. For example, a quote inside a string gets a backslash in front of it.
What is the difference between escape and unescape?
Escape turns raw text into a safe string. Unescape does the reverse and gives you the plain text back.
Which formats does it support?
HTML, XML, JavaScript, JSON, Java, C#, Python, PHP, SQL, CSV, add slashes, URL percent encoding and regex.
How do I escape HTML?
Pick HTML and paste your text. The tool turns the ampersand, the angle brackets and the quotes into entities.
How do I escape a JavaScript string?
Pick JavaScript, choose your quote, and paste your text. New lines, tabs, backslashes and the chosen quote get escapes.
How do I escape quotes in a string?
Pick the language, then choose double or single quotes. The tool puts a backslash before that quote. SQL doubles it instead.
How do I escape a SQL string?
Pick SQL. Every single quote doubles. Tick MySQL backslash style if your database uses backslash escapes.
Is escaping enough to stop SQL injection?
No. Use prepared statements with parameters. Escaping suits quick fixes and reading data, not a secure design.
How do I escape a CSV field?
Pick CSV. The tool doubles the quotes and wraps the field in quotes when it holds a comma, a quote or a line break.
What does Add slashes do?
It puts a backslash before single quotes, double quotes and backslashes, like the PHP function addslashes.
How do I encode a URL?
Pick URL percent encoding. Unsafe characters become a percent sign and two hex digits.
What does Declare a variable do?
It wraps the escaped string in a declaration, such as const text = "..."; in JavaScript. Pick a name in the box.
How do Java, C# and Python differ?
They share most escapes, but each has details of its own. The tool follows the rules of the language you pick.
What does Escape non-ASCII characters do?
It turns accented letters and symbols into Unicode escapes or numeric entities, so the text survives any file encoding.
Can I unescape a string with quotes around it?
Yes. The tool removes the outer quotes, and a variable declaration too, before it reads the escapes.
What happens with an unknown escape?
The tool keeps the character after the backslash. Python keeps the backslash too, as Python itself does.
Can I convert a file?
Yes. Use Open a file. TXT, CSV, JSON, XML, HTML, SQL, JavaScript, Markdown and log files work.
How big a text can I convert?
A few megabytes. Very large texts may take a moment on a phone.
What does Swap sides do?
It moves the result into the left box and flips the direction, so you can check a round trip.
What is the regex format for?
It adds a backslash before every special regex character, so a literal phrase matches as plain text.
Does it work on a phone?
Yes. The panels stack and the boxes scroll. So you can escape text on the go.
Handy Companions For Encoding Work
Escaping is one step. These three tools help with the rest.
HTML Entity Encoder
Encode and decode named and numeric HTML entities.
Open tool →URL Encoder
Encode and decode URLs and query strings.
Open tool →JSON Stringify
Turn JSON into a string and back again.
Open tool →
Ready To Escape Some Text?
Pick a format, paste your text, and copy the result. The tool is free, needs no account, and keeps every character on your device.