Encoding Tools
HTML Entity Encoder / Decoder
Encode special characters to HTML entities and decode them back. Supports named (&), decimal (&), and hex (&) entity styles. Runs entirely in your browser.
What are HTML entities?
An HTML entity is a text string that begins with an ampersand (&) and ends with a semicolon (;). Entities represent characters that have special
meaning in HTML markup, such as the less-than sign (<) and the ampersand
itself, or characters that are difficult to type directly, such as non-breaking spaces or
accented letters.
Without entity encoding, a stray < or & in text content can confuse
the browser's HTML parser, causing rendering errors or, in the worst case, creating an XSS vector
when user-supplied text is inserted into a page.
Named, decimal, and hex entities
HTML5 supports three entity formats, all of which produce identical output in the browser:
- Named: uses a mnemonic name:
&,<,>,",', . Named entities exist only for a fixed set of characters. For all other characters this tool falls back to hex notation. - Decimal: uses the Unicode code point in base 10:
&for&,<for<. Works for any Unicode character. - Hex: uses the code point in hexadecimal:
&for&,<for<. Preferred in CSS and SVG contexts and by most minifiers.
Which characters are encoded?
This tool encodes characters that require escaping for safe HTML output:
-
&->&: must always be escaped -
<-><: prevents accidental tag interpretation -
>->>: prevents closing tag confusion -
"->": safe inside double-quoted attributes -
'->': safe inside single-quoted attributes - All non-ASCII characters (code points above U+007F): ensures ASCII-only HTML source compatibility
Common use cases
- Sanitizing user input for HTML insertion: encode text content before inserting it into a web page to prevent cross-site scripting (XSS).
- Writing HTML by hand: encode special characters in content so the browser renders them literally rather than interpreting them as markup.
- Debugging encoded HTML: paste a snippet full of entities into Decode mode to read it as plain text.
Security framing: XSS prevention
Failing to HTML-encode user-supplied input before inserting it into the DOM is the root
cause of Cross-Site Scripting (XSS), consistently ranked as one of the most
common and impactful web vulnerabilities (OWASP Top 10). An attacker who can inject
<script> tags or event handlers via unescaped input can steal session cookies,
redirect users, or perform actions on their behalf. Always encode output at the point of insertion
- not just at the point of input.
Content Security Policy (CSP)
HTML entity encoding alone is not sufficient to prevent all XSS attack vectors. Browsers
support a Content-Security-Policy response header that specifies which sources
of scripts, styles, and other resources are trusted. A strict CSP (e.g.,
script-src 'self') provides a critical defense-in-depth layer that limits the
damage if encoding is missed or bypassed. Use both encoding and CSP together.