← Cryptography guide

K093 / Encoding and decoding

HTML entities

HTML character entity encoding · Survey date 2026-12-05

Character sequences in HTML documents used to represent reserved or special characters.

CRYPTOGRAPHY LAB / K093

Cryptography Lab · HTML entities

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Limited implementation

HTML entities (five-character text escaping)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

Definition and overview
Character sequences in HTML documents used to represent reserved or special characters. Source document ↗
Classification and reversibility
Reversible encoding, not encryption or hashing; browsers substitute entities with original characters. Source document ↗
Key or secret requirements
Not confirmed in the survey
Operating principle and structure
Named, decimal and hexadecimal forms; case-sensitive. Source document ↗
Key size, block size and parameters
Not confirmed in the survey
Security strength and recommendation
Recommended output encoding for safely displaying user input. Source document ↗
Known attacks and vulnerabilities
Some entity decoders omit named entities, potentially permitting filter bypasses. Source document ↗
Standards and certification
WHATWG HTML named character reference list distinguishes amp and amp; entries. Source document ↗
Typical uses
Context-appropriate HTML output encoding to mitigate XSS. Source document ↗
Implementations, libraries and tools
JavaScript he and other entity encoders/decoders. Source document ↗
Decryption or decoding
Decode with specified text/attribute context, semicolon and error policies. Source document ↗
Advantages
Safely represents invisible, ambiguous or code-conflicting characters. Source document ↗
Limitations and cautions
Semicolon omission rules vary by version/implementation and may be unsafe. Source document ↗
Distinguishing encryption, encoding and hashing
Contextual escaping to prevent data being interpreted as code, not encryption/hashing. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

When displaying Tom & Jerry <3 in HTML text, encode it as Tom &amp; Jerry &lt;3; the browser displays the original characters.

Procedure

Identify HTML text, attribute, URL or JS context; escape dangerous characters such as &, <, > and quotes with the appropriate context-specific function. Decode only when needed using explicit context/semicolon policy. No secret key.

Scenario

Encode forum comments before rendering rather than inserting raw input. Security inspection systems should support standard named references and semicolon variants when decoding.

Pitfalls and alternatives

Missing semicolons, incomplete named-entity decoders and wrong output contexts may cause bypasses and XSS. Use vetted libraries and context-specific output encoding instead of relying only on input filters.

References