ARYXTOOLS

Free Online Tools

ARYXTOOLS

HTML Entities Encoder/Decoder

Encode text to HTML entities or decode entities back to text, named, decimal, or hex.

Format:
Scope:
<p class="intro">Café & "quotes" - 100% safe</p>

More developer tools

Type a less-than sign into an HTML page without thinking about it and the browser reads it as the start of a tag, not as a character you meant to display. HTML entities exist to fix that, a way of writing a character that would otherwise get misread as markup, so it shows up on screen exactly as intended. This tool converts text into entities and back, in named, decimal, or hexadecimal format, entirely in your browser.

What this tool does

Paste text or HTML and encode it into entity form, or paste already-encoded entities and decode them back to plain text. Three output formats are available for encoding: named entities like &, decimal numeric entities like &, and hexadecimal entities like &. Two scopes control how aggressively encoding runs, "only unsafe characters" touches exactly the five characters that can break HTML markup, while "all non-ASCII too" also converts accented letters, symbols, and emoji into entities. Decoding reads all three entity formats at once and reverses them, whichever format the input happens to use.

How to use it, step by step

  1. Choose Encode or Decode.
  2. If encoding, pick a format, named for readable output, decimal or hex if a system you are feeding this into expects numeric entities specifically.
  3. Choose a scope. "Only unsafe characters" is the right default for most HTML work. Switch to "all non-ASCII too" if you need every accented letter or symbol converted, useful for older systems with limited character encoding support.
  4. Paste your text or entities into the input box.
  5. Read the result below, and copy it, or click "Use as new input, swap mode" to reverse the operation on what you produced.

Who this is for

Developers displaying user-submitted content safely need to encode the handful of characters that could otherwise be misread as markup, a defense against a class of security bug called cross-site scripting. Anyone writing a tutorial or documentation that shows raw HTML code as text, rather than letting the browser render it, needs the angle brackets encoded so the example displays instead of executing. Email template developers deal with inconsistent entity support across email clients and often need to check both directions, what an entity decodes to and what format a given client expects. Web scrapers pulling data from HTML pages frequently need to decode entities like & and ' back into plain text before the data is usable.

Why five characters matter more than the rest

HTML gives special meaning to a small set of characters. The less-than and greater-than signs open and close tags. The ampersand starts an entity reference. Double and single quotes wrap attribute values. If any of these appear inside HTML content where the parser expects markup, the result ranges from a rendering glitch to a security hole, depending on where the unencoded character lands.

This is the actual reason encoding exists as a security practice, not only a formatting convenience. If a webpage takes user input, a comment, a username, a search query, and inserts it directly into the page without encoding it first, a person could submit text containing a literal <script> tag, and the browser would execute it as real code rather than displaying it as text. Encoding the five unsafe characters before inserting untrusted content into HTML closes that door. The content displays exactly as submitted, but a browser can no longer mistake it for markup or a script.

Named, decimal, and hex, and when each one matters

Named entities are the most human-readable option, & is instantly recognizable as an ampersand to anyone reading the source code. The tradeoff is coverage, HTML only defines named entities for a specific list of characters, a few hundred common symbols and accented letters, not the full range of possible characters a document might contain.

Numeric entities, decimal or hex, cover every character that exists, since they reference a Unicode code point directly rather than relying on a name being defined for it. An emoji, a rare symbol, a character from a script with no assigned named entity, all of these only have a numeric representation available. Hex entities are common in contexts working directly with Unicode code points, since code points are conventionally written in hexadecimal, &#x1F600; matches the same U+1F600 notation a Unicode reference table would use for that emoji. Decimal entities show up more in systems that generate entities programmatically, where converting a character code straight to a decimal number is a smaller step than converting it to hex first.

Scope: unsafe characters only, or everything non-ASCII

The default scope in this tool touches only the five characters that can break HTML parsing. Everything else, including accented letters and most symbols, passes through unencoded, which is fine in a modern HTML document served with UTF-8 encoding, the standard on essentially every website built today. Browsers handle UTF-8 characters directly with no need for entity encoding beyond the five unsafe ones.

The broader scope, encoding all non-ASCII characters, exists for older or more restrictive systems, certain email clients, legacy XML processors, or contexts where the character encoding of the destination is uncertain or limited to plain ASCII. Encoding every accented letter and symbol into an entity guarantees the content displays correctly regardless of what character encoding the receiving system assumes, at the cost of a much longer, less readable output string.

A worked example

Take a code snippet you want to show inside a tutorial: if (x < 10) { return true; }. Insert that directly into an HTML page and the browser reads < 10> as an actual tag, breaking the layout and hiding part of the example. Run it through this tool with named format and the unsafe-characters scope, and the less-than and curly braces that need it come back as if (x < 10) { return true; }, safe to drop straight into an HTML page's body content, where it renders as the literal text a reader is supposed to see.

Paste that encoded string back in with Decode selected, and the result matches the original snippet exactly, less-than sign, spacing, and all. That round trip, readable code in, safely displayable entities out, decoded code back, is the whole reason this class of tool exists for developers writing documentation.

How this differs from JavaScript string escaping

HTML entities and JavaScript escape sequences solve adjacent but separate problems, and mixing them up produces broken output in both directions. A JavaScript string containing a double quote needs a backslash escape, \", to avoid ending the string early, that escaping happens inside JavaScript source code, before the string ever reaches the page. HTML entity encoding happens at the opposite end, when a value is being inserted into the HTML document itself, regardless of what language generated that value.

A string that is going to end up as both, generated inside a JavaScript string and then inserted into HTML, sometimes needs both kinds of escaping applied in the correct order. Getting that order backwards is a common source of double-escaped or under-escaped output, text that shows a literal &amp; instead of a single ampersand, or the reverse, an unescaped character that should have been converted.

Common mistakes when working with entities

Double-encoding is the most frequent one, running already-encoded text through the encoder a second time turns & into &amp;, which decodes back to the literal text "&" instead of a plain ampersand. This tends to happen when content passes through more than one layer of a system that each apply their own automatic escaping, a template engine and a database layer, for instance, both encoding the same value independently. If a decoded result still contains entity-looking text with an amp; inside it, that is usually the sign, run Decode a second time to check.

Forgetting to decode entities before further processing text is the opposite mistake, common when working with scraped HTML. Text pulled from a webpage often arrives with entities still intact, a title containing &#39; instead of an apostrophe, and searching or comparing that text against plain strings silently fails until the entities are decoded first.

A note on what this tool will not do

Encoding the five unsafe characters prevents a browser from misreading submitted content as markup, but it is one piece of a larger security practice, not a complete defense on its own. Content that needs to go inside an HTML attribute, a JavaScript string, or a URL each has different characters that need escaping, and a framework's built-in templating system usually handles all of these contexts correctly by default. Treat this tool as useful for understanding what encoding does and for quick one-off conversions, not as a substitute for a templating system that already escapes output correctly for the context it is rendering into.

If you are also working with data that needs to survive being placed inside a URL rather than HTML markup, the encoding rules are different, the URL encoder/decoder covers percent-encoding, the equivalent concept for URLs instead of HTML. If the content you are encoding needs to move as binary data rather than displayable text, the Base64 encoder/decoder handles that different kind of conversion.

Frequently asked questions

Those characters mark the start and end of HTML tags, so a browser reading a literal < or > in page content interprets it as the beginning of markup rather than as text. Encoding them as &lt; and &gt; tells the browser to display the character itself instead of treating it as a tag.

The ampersand itself starts every HTML entity, so a literal & in content needs to be encoded as &amp; to avoid being misread as the start of some other entity. This is why the ampersand is one of the first characters any HTML encoder escapes.

Encoding user-supplied content before displaying it is one real defense against a category of attack called cross-site scripting, since it prevents a malicious &lt;script&gt; tag from being interpreted as executable markup. It is one layer of defense, not a complete security solution on its own.

Rare or less common entities may not decode if the exact entity name is not recognized, though standard entities like &lt;, &gt;, &amp;, and &quot; are always handled. Numeric entities, written as &#60; for example, are also supported directly.

Store the raw, unencoded text in the database, and encode it only at the point of displaying it in HTML. Encoding before storage makes the stored data harder to reuse elsewhere, like in an API response or a different output format that does not expect HTML entities.