HTML Entities Encoder/Decoder

Free HTML Entities Encoder and Decoder — convert special characters to safe HTML entities and back. Prevent XSS attacks, fix broken characters in web pages, and ensure proper display of special symbols. Includes complete HTML entity reference table.

Free online tool · Developer Tools · No installation · No sign-up required

Overview

HTML entities are a fundamental aspect of web development, providing a mechanism to display characters that have special significance in HTML or are not readily available on a standard keyboard. These entities are placeholders, or character references, that a browser interprets and renders as the intended character. For instance, the less-than symbol (<) is a reserved character used to start an HTML tag. To display it as text, one must use its corresponding entity, either the named entity `&lt;` or the numeric entity `&#60;`. This system ensures that the browser\'s parser doesn\'t confuse content with markup, preventing rendering errors and maintaining the structural integrity of the document. Understanding and utilizing HTML entities is crucial for any developer aiming to create robust and error-free web pages, especially when dealing with dynamic content or user-generated input where the presence of special characters is unpredictable.

The technical implementation of HTML entities is rooted in character encoding standards like ASCII and Unicode. Each character is mapped to a unique numeric code point. HTML entities can reference these characters either by a descriptive name (e.g., `&copy;` for the copyright symbol) or by their numeric code point in decimal (`&#169;`) or hexadecimal (`&#xA9;`) format. While named entities are more memorable and improve code readability, numeric entities offer broader compatibility, especially for less common characters or symbols that may not have a designated name. The choice between named and numeric entities often depends on the specific use case, with developers balancing readability against the need for comprehensive character support. Modern web development heavily relies on UTF-8, a variable-width character encoding that can represent every character in the Unicode standard, making the use of entities for special characters seamless and consistent across different platforms and browsers.

The importance of HTML entities extends beyond simply displaying special characters. They play a vital role in web security, particularly in preventing Cross-Site Scripting (XSS) attacks. When a website displays user-provided input without proper sanitization, malicious actors can inject scripts containing HTML tags. By converting special characters like `<` and `>` into their corresponding entities, developers can neutralize these scripts, ensuring they are rendered as harmless text rather than being executed by the browser. Furthermore, using entities for special characters ensures cross-platform and cross-browser compatibility, as it guarantees that symbols will be displayed correctly regardless of the user\'s operating system or browser, which might otherwise misinterpret or fail to render certain characters. Therefore, a solid grasp of HTML entities is not just about proper rendering but is a cornerstone of secure and universally accessible web development.

Worked example

A product title with an ampersand and quotes going into an attribute

A shop owner has the product title Bob's "Classic" T-Shirt & Mug — 12 oz and needs it inside the title attribute of a link without breaking the attribute, without breaking the text, and with a clear idea of what the numeric alternative looks like.

  1. Open the Encode tab, leave Entity Type on Named, and leave the spaces checkbox off so that spaces stay spaces and the title stays readable in the source.
  2. Paste the 37-character title. The output box fills as you type and reads Bob&apos;s &quot;Classic&quot; T-Shirt &amp; Mug &mdash; 12 oz.
  3. Four characters were replaced: the apostrophe became &apos;, each double quote became &quot;, the ampersand became &amp; and the em dash became &mdash;. The letters, the digits, the hyphens and every space were left alone.
  4. Paste that into the attribute: title="Bob&apos;s &quot;Classic&quot; T-Shirt &amp; Mug &mdash; 12 oz". The quotes inside the value are entities now, so the title cannot terminate the attribute early, which is the bug this pass exists to prevent.
  5. Switch Entity Type to Numeric to see the other option: the same title becomes 37 decimal references, from &#66; for the B to &#122; for the z, 201 characters in total. Every character including each space is replaced, so nothing is left literal.
  6. Press Copy and use the result where it is needed. The Rendered HTML Preview panel shows what a browser makes of the text, inside a sandboxed frame where scripts, forms, popups and same-origin access are all disabled.
  7. To go back the other way, switch to Decode and paste &amp;lt;p&amp;gt;Hello&amp;lt;/p&amp;gt;. The tool warns that the input looks double-encoded, because one pass returns &lt;p&gt;Hello&lt;/p&gt; and the markup appears only after a second pass.

Result: The title goes into the attribute as Bob&apos;s &quot;Classic&quot; T-Shirt &amp; Mug &mdash; 12 oz, with the quote and the ampersand escaped while the spaces stay spaces. When named entities are not an option, the numeric mode produces the same title as 37 references and 201 characters.

How to use HTML Entities Encoder/Decoder

  1. Enter text
  2. Click Encode or Decode
  3. View entities
  4. Copy to clipboard

Common mistakes

Running a full URL through the HTML entity encoder to make it safe.

The encoder covers markup characters and a list of typographic ones; it does not touch spaces, question marks, equals signs, hashes or non-ASCII letters, although the ampersand does become &amp;. A URL with a space in it is still broken, and anything that reads the value outside an HTML parser, such as a spreadsheet, a redirect header or a plain-text mail, receives the literal characters &amp; and &quot;. Use url-encoder for the URL and this tool only for the HTML that wraps it.

Assuming that named encoding escapes everything that could be dangerous.

Named mode knows a fixed table of 35 characters, so accented letters, emoji, currency signs outside the table and every other code point are passed through unchanged. For text that must survive a pipeline which mangles bytes, or for a document in a language without named entities, switch to Numeric, which replaces every character with its decimal code point.

Decoding untrusted markup and then rendering it in a page.

Decoding is a text transformation, not a sanitiser: a payload comes back as live markup, and inserting that into a document is an injection. The preview here is confined to a sandboxed frame for exactly that reason. Treat the decoded output as data and escape it again at the point where it enters a page.

Wondering why one decode pass leaves entities behind in the text.

Double-encoded input such as &amp;amp; needs two passes, and the tool shows a warning when it sees the pattern. Decode until the text stops changing, but remember that each pass converts more of the original markup into live characters, which is the opposite of what a safety check wants.

Features

Limits worth knowing

When to use it

Practical tips

Why use this tool

When this is not the right tool

Frequently asked questions

HTML entities?

Special codes for characters: &amp; for &, &lt; for <.

Why use?

Correct display and XSS security prevention.

Named vs numeric?

Named (&amp;) readable. Numeric (&#38;) for any Unicode.

Common ones?

&lt; &gt; &amp; &quot; &apos; &nbsp;

Related tools in Developer Tools

Further reading

HTML Entity Encoder/Decoder: Convert Special Characters

Encode special characters to HTML entities or decode entities back to characters. Prevent XSS and display special characters correctly.