Skip to main content
riqo.ioTools for big ideas

HTML entity encoder and decoder

Encode characters as HTML entities or decode entity references back to text.

Operation

Note

This tool does not sanitize HTML and does not provide XSS protection.

Result

Description

Performs text transformations using HTML entity rules only. It does not parse the DOM, sanitize HTML or automatically protect against XSS.

Instructions

Choose Encode to transform special characters or Decode to resolve entities. Treat output as text until it has been validated for the target application context.

Use cases

Read HTML entities

Prepare textual HTML examples

Compare encoded and decoded text

Examples

Special characters

Input

<tag>

Output

&lt;tag&gt;

Frequently asked questions

Is this an HTML sanitizer?

No. It does not remove dangerous markup and is not XSS protection.

Can I insert the output directly into the DOM?

Only after applying the escaping and sanitization rules required by that context.

In-depth guide

HTML entities, escaping and markup security

HTML character references, numeric references, contextual escaping, sanitization and their relationship to XSS prevention.

Why character references exist

HTML reserves some characters for markup syntax. Character references represent characters when a literal form would be ambiguous, inconvenient or unavailable, using names such as &amp; or numeric references.

Modern HTML handles Unicode directly, so not every non-ASCII character needs an entity. References are mainly useful for syntax-sensitive characters and conventional representations.

Named and numeric references

Named character references map standardized names to characters or sequences; numeric references identify a Unicode code point in decimal or hexadecimal form. The HTML parser resolves both into resulting text.

A numeric reference identifies a Unicode code point, not the UTF-8 bytes used to transport the document. File encoding and entity syntax are separate layers.

Escaping is context-dependent

HTML text, attribute values, URLs, CSS and embedded JavaScript have different grammars. Correct escaping must know the output context: a replacement suitable for a text node can be insufficient or incorrect inside a script.

Secure template engines therefore apply contextual escaping. Disabling auto-escaping or manually concatenating markup with untrusted data increases the chance that data becomes executable syntax.

Escaping versus sanitization

Escaping keeps data as text inside a specific context. Sanitization accepts potentially active markup and removes or restricts elements, attributes and URLs according to a policy.

If users are allowed to submit a subset of HTML, replacing angle brackets is not enough. Use a maintained HTML sanitizer that operates on parsed structure.

XSS and trust boundaries

Cross-site scripting occurs when attacker-controlled data reaches an executable browser context. Prevention combines contextual output encoding, sanitization where HTML is accepted and APIs that avoid dangerous sinks.

Entities are not a universal security filter: data can be safe in one text context and dangerous after decoding or reinsertion elsewhere. Follow the full data flow.

Best practices

Keep UTF-8 end-to-end, rely on framework escaping where possible and avoid repeated encode/decode cycles without a clear contract. Test quotes, ampersands, syntax characters and Unicode at boundaries.

When the goal is plain text, use APIs that create text nodes. When markup is required, define an allowlist and use mature sanitization libraries rather than regular expressions or ad-hoc substitutions.

Open the full guide