CalculatorsConvertersDeveloperTextAll toolsDirectory
Submit your tool Sign in
Theme
Home/Answers/Developer
How-to

How do I escape HTML special characters?

Short answer

Paste your text into a browser-based HTML entity encoder and it converts characters like less-than, greater-than and ampersand into their safe entity equivalents such as <, > and &. Escaping happens on your device, and it is the correct way to show code or user text on a page without the browser trying to render it as markup.

Why raw characters break or endanger a page

A browser reads < and > as the start and end of tags, and & as the start of an entity. If you drop raw text containing those characters into HTML, the page either renders wrong or, when the text came from a user, becomes an opening for cross-site scripting. Escaping replaces each dangerous character with its entity, so it displays as a literal character instead of being interpreted as code.

Encode to display, decode to read

The tool goes both ways. Encoding turns your text into entities so you can safely paste code samples into a blog post or documentation. Decoding turns entities back into their characters, which is handy when you copy text out of HTML source and want the plain version. Note that in a real application you should rely on your framework's escaping; this tool is for one-off snippets and understanding what the entities are.

Step by step

  1. Paste your text. Paste the text or code containing special characters.
  2. Encode locally. The tool converts the characters to HTML entities in your browser.
  3. Copy the escaped text. Copy the entity-encoded text into your HTML source.

Frequently asked questions

Which characters get escaped?

The HTML-significant ones, chiefly less-than, greater-than, ampersand and quotes, become entities like &lt;, &gt;, &amp; and &quot;.

Can it decode entities back to text?

Yes. The tool encodes and decodes, so you can turn &lt; back into a literal less-than sign.

Is my text uploaded?

No. Encoding and decoding run entirely in your browser.

Related answers