← Back to Home

Escape & Unescape Text

Safely handle special characters in your data for any context.

What is Text Escaping?

Common Characters to Escape

Character HTML Escape Reason
< &lt; Interpreted as the start of an HTML tag.
> &gt; Interpreted as the end of an HTML tag.
& &amp; Used to begin character entities.
" &quot; Can prematurely close an attribute value in HTML.
' &#39; Can prematurely close an attribute value in HTML.

Use Cases for Developers

  • Displaying Code Snippets: Safely show HTML, XML, or other code on a web page without it being executed by the browser.
  • Storing User Input: Escape user-provided text before saving it to a database to prevent SQL injection and other attacks.
  • Generating Dynamic HTML: Ensure that data from a database or API is displayed correctly as text within your HTML structure.
  • Working with JSON/XML: Make sure strings containing special characters are correctly formatted within JSON or XML data structures.

Frequently Asked Questions:

What's the difference between escaping and encoding?

'Escaping' is about making data safe for a specific context (like HTML), while 'encoding' (like URL encoding or Base64) is about transforming data for transmission or storage. They are related but serve different primary purposes.

When should I unescape text?

You typically unescape text when you retrieve it from a safe context (like a database) and want to display it in its original, human-readable form, for example, in a text editor or a form field for editing.