</> HTML 实体编解码

在线 HTML 实体编码/解码,支持命名实体、十进制和十六进制数字实体

(默认仅编码特殊字符:& < > " ')
🔒 HTML 编码
输入文本 编码结果
🔓 HTML 解码
输入 HTML 实体文本 解码结果

What is HTML Entity Encoding/Decoding?

HTML entities are a mechanism for representing special characters using special strings in HTML documents. Since HTML uses < and > to define tags, displaying these characters directly on a page would cause the browser to misinterpret them as actual tags. Additionally, & marks the start of an entity and must also be escaped. HTML entity encoding replaces special characters with entity references starting with & and ending with ;, ensuring text is safely and correctly rendered in HTML pages while preventing XSS (Cross-Site Scripting) attacks.

Three Types of HTML Entities

1. Named Entities

Use predefined mnemonic names to represent special characters. The most commonly used ones include:

CharacterNamed EntityDescription
&&amp;Ampersand
<&lt;Less than
>&gt;Greater than
"&quot;Double quote
&apos;&apos;Apostrophe (single quote)
&nbsp;Non-breaking space
©&copy;Copyright symbol
®&reg;Registered trademark

2. Decimal Numeric Entities

Format: &#number;, where the number is the character's Unicode code point in decimal. For example: &#60; represents <, &#38; represents &. This representation can encode any Unicode character, unrestricted by the named entity list.

3. Hexadecimal Numeric Entities

Format: &#xhex-digits;, e.g. &#x3C; represents <, &#x4F60; represents the Chinese character "你". The hexadecimal form is more common in web development because it aligns with the standard Unicode code point notation (U+XXXX), making it easier to reference and use.

Practical Uses of HTML Entity Encoding

  • Displaying Code Snippets: When showing HTML/XML source code on a web page, < and > must be encoded; otherwise, the browser will render the code content as actual HTML elements.
  • Form Security: Entity-encoding user input effectively prevents XSS injection attacks. For example, when a user inputs <script>alert("XSS")</script>, after encoding it becomes &lt;script&gt;alert("XSS")&lt;/script&gt;, which the browser displays as plain text instead of executing it.
  • Data Storage & Transport: When embedding HTML content in data formats like JSON, XML, or RSS, special characters must be encoded to prevent document structure corruption.
  • Email Content Handling: Dynamic content embedded in HTML emails needs encoding to prevent formatting issues.
  • CMS Content Management: User-generated content (UGC) stored in content management systems should be encoded before display to ensure security and correct formatting.

Why Use Our Online HTML Entity Tool?

Compared to manually replacing characters one by one or memorizing all entity names, our online HTML Entity Encoder/Decoder provides an intuitive two-panel interface — encode on the left, decode on the right — with all operations performed locally in your browser. No software installation required and no data is ever uploaded to any server. Easily toggle between "encode only special characters" and "encode all characters" modes to suit different scenarios. The real-time preview lets you see results as you type, plus Ctrl+Enter shortcut and copy buttons greatly boost your development efficiency. Whether you're a frontend developer writing code examples, a security engineer testing XSS protection, or a content editor handling special characters, this is your go-to tool.