HTML gives a handful of characters a special meaning: the angle brackets delimit tags, the ampersand starts an entity, and the quotes wrap attribute values. The moment you want to display one of those characters literally — to show a code sample, to echo back what a user typed — you have to represent it some other way. That other way is the HTML entity, and this HTML entity encoder converts them in both directions — encoding special characters into entities or decoding entities back to text.
Encoding: text to HTML entities
Encoding replaces the reserved characters with their entity form:
With those escaped, a snippet like <script>alert(1)</script> renders as visible text instead of executing, which is the whole basis of output encoding as a defence against cross-site scripting.
Decoding: HTML entities back to text
Decoding runs the other way and understands all three reference forms. A named entity such as © becomes ©, a decimal reference such as © becomes ©, and a hexadecimal reference such as © becomes © as well. Content copied from a page source, an email template or an exported CMS field is usually full of these, and decoding turns it back into something you can actually read.
HTML entities are not the only encoding
It is easy to conflate the different text encodings, but they solve different problems:
HTML entities make reserved characters safe to display in markup.
URL (percent) encoding makes characters safe to carry in a web address, turning a space into %20.
Base64 turns arbitrary binary data into ASCII text so it can travel through text-only channels.
This HTML entity encoder handles the first. For the other two there are dedicated URL and Base64 converters, and picking the right one is what stops a string from being mangled on the way into — or out of — a page.
When to use the HTML entity encoder
The HTML entity encoder is useful whenever you place user-supplied or code-like text into an HTML context. Encoding the angle brackets and ampersand stops the browser from treating that text as tags, which both preserves what the user sees and removes a cross-site scripting vector. For decoding, paste content copied from a page source, an email template or a CMS export and the encoder converts named references like ©, decimal references like © and hexadecimal references like © back into the characters they represent.
Both directions run in the browser. Snippets, tokens and private copy are converted locally with no request and no logging.