Convert · Text tools

HTML Entity Encoder

Escape or unescape common HTML entities for safe display in markup.

What is HTML Entity Encoder?

An HTML entity encoder replaces five markup-sensitive characters with entity references, while the decoder reverses a small fixed set of named and numeric references. It helps display literal snippets such as `<div>` as text rather than interpreting their angle brackets as markup.

Encoding changes ampersand, less-than, greater-than, double quote, and apostrophe. Decoding recognizes `&lt;`, `&gt;`, `&quot;`, `&#39;`, `&apos;`, and `&amp;` with exact lowercase spelling. It is not a complete HTML parser, sanitizer, or general Unicode entity codec.

Why Use This Tool?

HTML gives a few characters structural meaning. Escaping them is useful when placing literal text into an HTML text context or showing code examples.

  • Display angle brackets and ampersands literally.
  • Prepare simple text for an HTML snippet.
  • Decode the specific common entities supported by the tool.
  • Inspect escaped copy from a CMS or template.

How Does This Tool Work?

Encoding replaces ampersands first. That ordering prevents the ampersands introduced by later entity strings from being encoded again during the same pass. Apostrophes become the decimal numeric reference `&#39;`; the other four use common named references.

Decoding performs a fixed series of literal, case-sensitive replacements and decodes ampersand last. This ordering allows text such as `&amp;lt;` to become `&lt;` after one pass, not `<`. Running decode again would decode that newly exposed entity.

Understanding Your Results

The encoder's result is suitable only for contexts whose escaping requirements match these five characters. HTML attributes, URLs, CSS, JavaScript, JSON, SQL, and rich HTML each have different rules. Entity encoding is not the same as removing unsafe elements or attributes.

The decoder does not recognize general decimal references such as `&#60;`, hexadecimal references such as `&#x3C;`, `&nbsp;`, or the full HTML named-character-reference set. Uppercase spellings also remain unchanged.

Why Tracking This Matters

Correct contextual escaping helps browsers distinguish data from markup. Security requires trusted framework escaping and sanitization appropriate to the output context; a small manual converter should not be used as an XSS security boundary.

Benefits of Using HTML Entity Encoder

  • Encodes five common sensitive characters
  • Decodes a documented fixed set
  • Predictable literal replacements
  • Useful for simple code examples
  • Instant two-way workflow
  • Browser-local processing

How Is the Result Calculated?

The result is produced by ordered literal replacements. It does not build a DOM, resolve the full HTML entity table, or inspect where the result will be inserted.

& → &amp;; < → &lt;; > → &gt;; " → &quot;; ' → &#39;

Entity reference
Text beginning with & and ending with ;.
Context
The HTML, attribute, script, URL, or other location receiving data.

Tips for Better Results

  • Encode plain text once rather than repeatedly.
  • Use your template framework's automatic escaping in production.
  • Use a proven sanitizer when allowing user-authored HTML.
  • Do not apply HTML escaping to URLs or JavaScript as a substitute for their rules.
  • Expect unsupported named or numeric entities to remain unchanged.

Conclusion

HTML Entity Encoder is a focused helper for five common characters and a small decoder set. Use it for simple text preparation, while relying on contextual production escaping and sanitization for security.

Privacy & how it works

This text tool processes your input in the browser. Your text is not uploaded to The ToolSphere servers for this tool. Privacy Policy.

FAQ

Which characters does encoding change?expand_more

Ampersand, less-than, greater-than, double quote, and apostrophe.

Does it encode every Unicode character?expand_more

No. All characters except those five are left unchanged.

Does decoding support numeric entities?expand_more

Only the exact decimal apostrophe reference `&#39;` is supported.

Will it decode &nbsp;?expand_more

No. That entity is outside the fixed decoder set.

Are entity names case-sensitive here?expand_more

Yes. Only the exact lowercase strings are replaced.

Why can decoding twice change the result again?expand_more

An encoded ampersand can reveal another entity string after the first pass.

Does encoding sanitize unsafe HTML?expand_more

No. It performs five replacements and does not analyze elements, attributes, or URLs.

Can I rely on it to prevent XSS?expand_more

Not as a general security control. Use contextual framework escaping and an established sanitizer where needed.

Is this tool free?expand_more

Yes. No signup and no paywall for core use.

Is my text uploaded?expand_more

No for this tool. Text stays in your browser while you work.

Do I need an account?expand_more

No. Open the page and start typing or pasting.

Suggest an improvement

Tell us what would make this tool more useful. We read every suggestion.

Feedback for: HTML Entity Encoder