Allio Tools Pro — No ads · Bulk processing · Save historyUpgrade $2.99/mo →
🚀Allio Tools Pro
  • No ads
  • Bulk tools
  • History
$2.99/mo

在线免费HTML编码/解码器

Thanks for rating!

即时编码和解码HTML实体。

🚀Allio Tools Pro
  • Zero ads everywhere
  • Bulk processing
  • Save history
Upgrade — $2.99/moNo signup required
Allio Tools Pro — No ads · Bulk processing · Save historyUpgrade $2.99/mo →

Who uses the HTML编码/解码器?

  • 在渲染到 HTML 前清理用户生成内容以防止 XSS 的网页开发者。
  • 在文章和博客文章的 HTML 中编码引号、和号等特殊字符的内容作者。
  • 把从 CMS 或抓取页面中粘贴来的 HTML 实体解码回纯文本的开发者。

How the HTML编码/解码器 works

1

将文本或 HTML 内容粘贴到输入框中。

2

点击 Encode HTML Entities,将 & < > " ' / 转换为对应的 HTML 实体。

3

或点击 Decode HTML Entities,把 HTML 实体(包括 &copy; 这类命名实体)转换回普通字符。

4

用 Copy 按钮复制结果,或点击 Clear 重新开始。

Tips & tricks

  • Encode 只处理 & < > " ' / 这六个字符——它不会把 © 或长破折号转换成实体,所以不要依赖它做完整的符号转实体处理。
  • Decode 能处理浏览器识别的任何有效 HTML 实体,不仅限于 Encode 生成的那六种——它使用的是浏览器自带的 HTML 解析器。
  • 手动编写实体时,一定先编码 & 字符——如果最后才编码它,会导致已经写好的实体被二次编码。
  • 结果下方的字符计数行会准确显示编码或解码后文本变长(或变短)了多少。

Frequently Asked Questions

什么是 HTML 实体,为什么需要它?

HTML 实体是代表在 HTML 中具有特殊含义的字符的文本代码:< 表示标签开始,& 表示实体开始,> 表示标签结束。为了让这些字符在 HTML 中按字面显示而不被解释为标记,需要对其编码:< → &lt;,& → &amp;。

HTML 编码和 URL 编码有什么区别?

HTML 编码把字符转换为 HTML 实体,用于在网页上安全显示(&amp;、&lt;、&gt;)。URL 编码把字符转换为百分号编码序列,用于 URL 中(%26、%3C、%3E)。二者用途不同,不能互相替代。

这个工具会编码哪些字符?

Encode 恰好转换六个字符:& → &amp;,< → &lt;,> → &gt;," → &quot;,' → &#39;,/ → &#x2F;。它不会把 © 或 — 之类的其他符号转换成实体;如需这些符号,请直接插入对应的实体代码。

命名实体和数字实体有什么区别?

命名实体(&amp;、&lt;、&copy;)更易读,但需要浏览器支持该特定名称。数字实体则使用十进制(&#38;)或十六进制(&#x26;)码点代替。本工具的 Decode 功能两者都能处理——它使用你浏览器自带的 HTML 解析器来解析任何有效实体。

在用户生成内容中什么时候应该使用 HTML 编码?

在将用户生成的文本插入 HTML 之前,务必先进行编码,以防止 XSS(跨站脚本)攻击。如果用户输入 <script>alert('XSS')</script>,将其编码为 &lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt; 后,它会作为文本显示,而不会被当作代码执行。

Is my data safe when using the HTML编码/解码器?

Completely safe. The HTML编码/解码器 processes everything locally in your browser. No input data, results, or usage information is ever transmitted to or stored on any server.

Can I use the HTML编码/解码器 output in commercial projects?

Yes. The HTML编码/解码器 is a utility tool and its output carries no licensing restrictions. You are free to use results in any project, commercial or personal.

Does the HTML编码/解码器 follow official standards?

Yes. The HTML编码/解码器 is built to comply with the relevant industry standard or specification for this utility type. If you encounter an unexpected result, verify your input against the specification — edge cases outside the standard may produce undefined behaviour.

💼 Reach 100K+ developers & creators — Advertise on Allio ToolsLearn More →