HTML Entity Encoder/Decoder — Encode & Decode HTML Entities
Encode and decode HTML entities instantly. Convert special characters to HTML entities and back between named, decimal, and hex entity formats.
The formula
Encode: & & | < < | > > | " " | ' ' Decode: Named (& → &), Decimal (& → &), Hex (& → &)
- &
- Named Entity
- &
- Decimal Numeric Entity
- &
- Hexadecimal Numeric Entity
- HTML Context
- HTML Parsing Context
How HTML Entities Works
Encode: & & | < < | > > | " " | ' ' Decode: Named (& → &), Decimal (& → &), Hex (& → &)
HTML entity encoding converts special characters (like <, >, &, ", ') into their corresponding HTML entity references so they display correctly in web pages without being interpreted as markup. Decoding reverses this process, converting entity references back to their original characters. Three formats are supported: named entities (&), decimal numeric entities (&), and hexadecimal entities (&).
- &
- Named Entity — A mnemonic name for a character preceded by an ampersand and followed by a semicolon. Examples: & for &, < for <, > for >.
- &
- Decimal Numeric Entity — A character reference using its Unicode code point in decimal format. The format is &# followed by the decimal number and a semicolon.
- &
- Hexadecimal Numeric Entity — A character reference using its Unicode code point in hexadecimal format. The format is &#x followed by the hex number and a semicolon.
- HTML Context
- HTML Parsing Context — The HTML spec defines where entity parsing applies. Entities are resolved in HTML content but not inside <script> or <style> blocks in modern browsers, though they should still be encoded for safety.
How to Use
- Select the mode: "Encode to Entities" to convert special characters, or "Decode to Text" to convert entities back.
- Enter or paste your input text in the text area — either raw text with special characters or text containing HTML entities.
- View the encoded or decoded output result, along with character counts for both input and output.
Quick Reference
| & → &amp; | Ampersand — must always be encoded in HTML to avoid ambiguous entity parsing |
| < → &lt; | Less-than — must be encoded to prevent being interpreted as an HTML tag opening |
| > → &gt; | Greater-than — encoded for symmetry with less-than, though not strictly required |
| " → &quot; | Double quote — must be encoded inside attribute values delimited by double quotes |
Common Uses
- •Displaying code snippets on blogs and documentation sites without breaking the page layout
- •Sanitizing user-generated content before rendering it in web applications to prevent XSS attacks
- •Encoding special characters in HTML email templates to ensure consistent rendering across email clients
- •Processing scraped web content that contains encoded characters back into readable text
- •Preparing data for XML documents where certain characters have special meaning and must be escaped
Understanding the Result
HTML entity encoding is a fundamental security and display technique in web development. When a web browser encounters HTML markup, it parses angle brackets (< >) as tag delimiters, ampersands (&) as entity starters, and quotes as attribute delimiters. If user-generated content or dynamic data containing these characters is inserted directly into HTML without encoding, it can break page rendering or introduce cross-site scripting (XSS) vulnerabilities. The encoding process converts these five essential characters into their corresponding entity references: & becomes &, < becomes <, > becomes >, " becomes ", and ' becomes ' (or ' in XHTML). The decoding process is more complex because there are three formats in widespread use. Named entities like &, <, and © are defined by the HTML specification and provide human-readable mnemonics. Decimal numeric entities like & reference characters by their Unicode code point in base 10. Hexadecimal numeric entities like & use base 16, which can be more convenient when referring to code points from Unicode charts. The HTML5 specification defines 2231 named character entities covering a wide range of symbols, punctuation, and international characters. When decoding, the entity parser must handle all three formats, plus edge cases like missing semicolons (which are tolerated in certain contexts per the HTML spec), invalid code points, and entities that decode to non-printable characters. This tool handles the full range of named entities and properly processes both decimal and hexadecimal numeric entities for comprehensive encoding and decoding support.
Frequently Asked Questions
- What characters should always be HTML-encoded?
- The five essential characters are: & (ampersand), < (less-than), > (greater-than), " (double quote), and ' (single quote/ apostrophe). The ampersand and less-than are the most critical because they directly affect how the browser parses HTML markup. Everything else is optional but recommended for special or non-ASCII characters.
- Is HTML encoding the same as URL encoding?
- No. HTML encoding uses entities like &lt; to display characters safely in HTML documents. URL encoding (also called percent-encoding) uses %20 for spaces and similar patterns to make data safe for URLs. They serve different purposes and are not interchangeable. For example, a space is &nbsp; in HTML but %20 in a URL.
- Does encoding prevent XSS attacks?
- HTML entity encoding is a critical defense against XSS but is not sufficient on its own. It prevents injection when inserting data into HTML body content but does not protect when inserting into <script> tags, event handlers (onclick), or CSS. A comprehensive XSS prevention strategy uses context-specific encoding (HTML, JavaScript, CSS, URL) combined with content security policies (CSP).
- What is the difference between ' and '?
- Both represent the apostrophe/single quote character ('). ' is defined in the XHTML and XML specifications but is NOT a valid HTML4 entity. ' (the decimal numeric entity) works in all versions of HTML. For maximum compatibility, ' is preferred over ' when encoding apostrophes in HTML documents.
Cite this calculator
TheCalcUniverse. "HTML Entity Encoder/Decoder — Encode & Decode HTML Entities." TheCalcUniverse, 2026, https://thecalcuniverse.com/devtools/html-entity-encoder/. Accessed July 24, 2026.
Embed this calculator on your site
You may also like
-
JSON Formatter
Format, validate, and beautify JSON data instantly. Paste messy JSON and get clean, indented output with synta…
-
Case Converter
Convert text between 9 case formats: camelCase, PascalCase, snake_case, kebab-case, dot.case, Title Case, Star…
-
JWT Debugger
Decode and inspect JSON Web Tokens (JWT) client-side. View the header, payload, and signature information with…
-
Markdown Editor
Write markdown in a live editor and preview the rendered HTML in real-time. Supports headings, bold, italic, l…