Skip to content

HTML and XML Entity Encoder Decoder

Direction
Rules
More options

Useful when the page or feed may be read with the wrong character set.

Result
—
References converted
—
Length change (characters)
—

Choose Encode to turn the five markup-sensitive characters into references: < becomes <, & becomes &, " becomes ". Choose Decode to reverse it, so © 2024 reads © 2024. XML rules accept only five names (amp, lt, gt, quot, apos); numeric forms like € work in both.

About this tool

Code samples in a blog post, a product name with an ampersand in an RSS feed, or a scraped string full of &quot; all need the same fix: replace characters with character references, or turn them back. This converter does both directions under HTML or XML rules. The difference matters: XML knows only five named entities, so   or é break an XML parser unless written as numbers, while HTML accepts over two thousand names. The table lists every reference touched, with its character, Unicode code point and how many times it appeared. One limit: decoding covers the common named references (Latin accents, punctuation, currency, arrows, Greek letters) plus every numeric form; rare HTML names are left as typed and listed in a warning.

How to use it

  1. Paste or open the text

    Paste markup or encoded text, or open a .html, .xml or .txt file; it is read in your browser.

  2. Pick Encode or Decode

    Encode escapes characters into references; Decode turns references back into characters.

  3. Choose HTML or XML rules

    XML uses &apos; and only five names; HTML uses ' for the apostrophe and knows many more names.

  4. Check the reference table

    Each row shows one reference, its character and code point; copy a single reference from its row.

Examples

Show a tag as text

Text or markup
<a href="x">Tom & Jerry</a>
Direction
Encode
Rules
HTML

Result Result: <a href="x">Tom & Jerry</a>
References converted: 7
Length change (characters): 26

  1. Encoded 7 references using the HTML named references.
  2. Length went from 27 to 53 characters.

Escaping the angle brackets, quotes and ampersand lets the link appear on a page as code instead of being rendered.

Named and numeric forms together

Text or markup
© 2024 €5 © €
Direction
Decode
Rules
HTML

Result Result: © 2024 €5 © €
References converted: 4
Length change (characters): -22

  1. Decoded 4 references using the HTML named references.
  2. Length went from 35 to 13 characters.

© and © are the same sign, as are € and €, so both pairs decode to identical characters.

An attribute value for XML

Text or markup
It's 5 > 3
Direction
Encode
Rules
XML

Result Result: It&apos;s 5 > 3
References converted: 2
Length change (characters): 8

  1. Encoded 2 references using the XML 1.0 predefined set.
  2. Length went from 10 to 18 characters.

XML has its own name for the apostrophe, &apos;, which is safe inside a single-quoted attribute.

How it is calculated

reference = &name; or &#decimal; or &#xhex; ⇔ one Unicode code point (WHATWG named references, XML 1.0 §4.6)

&name;
a named reference, such as & for U+0026
&#decimal; / &#xhex;
the code point written in base 10 or base 16

Encoding replaces &, <, > and the double quote with &, <, > and ". The apostrophe becomes &apos; under XML rules and ' under HTML, because &apos; was missing from HTML 4. With the non-ASCII option, characters above code 126 become a named HTML reference when one exists, otherwise a decimal one. Decoding reads numeric references in any range from 1 to 10FFFF except surrogates, and named ones from the selected set; anything else stays untouched so nothing is silently lost.

Sources

Use from code or an AI agent Free API · MCP

The same calculation is a free JSON API. No key needed. The answer is in result.stats.primary.

curl -X POST https://api.tools-directory.workers.dev/v1/tools/html-and-xml-entity-encoder-decoder \
  -H 'Content-Type: application/json' \
  -d '{"inputs":{"text":"<a href=\"x\">Tom & Jerry</a>","direction":"encode","flavor":"html"}}'

When not to use it

  • Escaping text for a URL query string needs percent-encoding, not entities.
  • Escaping alone does not make untrusted HTML safe to render; use a sanitizer.
  • Binary XML formats such as WBXML or Android's compiled XML need a dedicated parser.

Common mistakes

  • Encoding twice, which turns & into &amp; and shows the code on the page.
  • Using   or é in an XML file, where only five names are defined.
  • Forgetting the closing semicolon, so &copy 2024 may not decode everywhere.

Frequently asked questions

How do I decode HTML entities in JavaScript?

In a browser, set the string as the innerHTML of a textarea element and read its value, or use DOMParser and read textContent. Both run the browser's own HTML parser, so every named reference works. In Node there is no DOM, so a package such as 'he' or 'entities' does the job. To check a single string by hand, paste it here with Decode selected.

How do I decode HTML entities in Python?

Use html.unescape from the standard library: html.unescape('© 2024') returns '© 2024'. It knows the full WHATWG list of named references and numeric forms. For the opposite direction, html.escape escapes &, < and >, and also both quote marks unless you pass quote=False.

How do I HTML encode a string in Java?

The JDK has no built-in method. Apache Commons Text provides StringEscapeUtils.escapeHtml4 and escapeXml11, and the OWASP Java Encoder provides Encode.forHtml for output placed in a page. For a quick manual check, encode the same text here and compare: a < should come out as < and an ampersand as &.

How do I decode XML entities in Golang?

encoding/xml decodes the five predefined entities and numeric references automatically when it parses a document. For a loose string, html.UnescapeString from the standard library also handles them, plus HTML names. To escape, xml.EscapeText writes <, >, &, " and ' to a writer.

How do I decode XML entities in Swift?

Foundation's XMLParser resolves the predefined entities and numeric references while it parses, so element text arrives already decoded. For a plain string outside a document, Swift has no one-line call; you replace the five names and numeric forms yourself or use NSAttributedString with the HTML document type on Apple platforms.

Can I decode entities in a whole XML file?

Yes. Use the open-file button to load a .xml, .svg or .html file; it is read locally and never uploaded. Pick Decode and XML rules, and the result box shows the file with references replaced. Any name XML does not define, such as  , is kept and reported in a warning.

Is an HTML decoder the same as a URL decoder?

No. URLs use percent-encoding, where a space is %20 and an ampersand is %26. HTML uses references like & and . A link inside an href attribute can need both: percent-encoding inside the URL, then & for each ampersand separating query parameters in the markup.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, December 3). HTML and XML Entity Encoder Decoder. Tools Directory. Retrieved December 4, 2026, from https://directory.milunir.com/developer-tools/encoders-decoders/html-and-xml-entity-encoder-decoder/

MLA

Tools Directory Editorial Team. “HTML and XML Entity Encoder Decoder.” Tools Directory, 3 Dec. 2026, https://directory.milunir.com/developer-tools/encoders-decoders/html-and-xml-entity-encoder-decoder/. Accessed 4 Dec. 2026.

Chicago

Tools Directory Editorial Team. “HTML and XML Entity Encoder Decoder.” Tools Directory. Last modified December 3, 2026. Accessed December 4, 2026. https://directory.milunir.com/developer-tools/encoders-decoders/html-and-xml-entity-encoder-decoder/.

Link<a href="https://directory.milunir.com/developer-tools/encoders-decoders/html-and-xml-entity-encoder-decoder/">HTML and XML Entity Encoder Decoder – Tools Directory</a>