Skip to main content
SiteIndex
开发者可以使用

转义或解码HTML实体

将特殊字符转换为HTML实体,或解码实体以还原可读文本。

使用指南

交互式工具区

无需注册账号
HTML实体编码与解码

51 characters in · 51 characters out — the conversion updates live as you type.

Why escape? The XSS example

Inserted into a page unescaped, this user input would run as code:

<script>alert('XSS')</script>

Escaped, the browser displays it as harmless text instead:

&lt;script&gt;alert(&#039;XSS&#039;)&lt;/script&gt;
Copyable JavaScript snippets
escapeHtml
function escapeHtml(text) {
  return text
    .replace(/&/g, "&amp;")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;")
    .replace(/"/g, "&quot;")
    .replace(/'/g, "&#039;");
}
unescapeHtml
function unescapeHtml(text) {
  const textarea = document.createElement("textarea");
  textarea.innerHTML = text;
  return textarea.value;
}
Entity reference
CharacterNamedDecimalHexDescription
&&amp;&#38;&#x26;Ampersand — always escape this one first, or the other entities break
<&lt;&#60;&#x3C;Less-than sign — starts a tag if left raw
>&gt;&#62;&#x3E;Greater-than sign — closes a tag if left raw
"&quot;&#34;&#x22;Quotation mark — ends a double-quoted attribute value if left raw
'&apos;&#39;&#x27;Apostrophe — ends a single-quoted attribute value (&#039; is the widely compatible form)
␣&nbsp;&#160;&#xA0;Non-breaking space — renders as a space that cannot wrap or collapse
©&copy;&#169;&#xA9;Copyright sign
®&reg;&#174;&#xAE;Registered trademark sign
™&trade;&#8482;&#x2122;Trademark sign
€&euro;&#8364;&#x20AC;Euro sign
HTML实体编码与解码是什么?

将特殊字符转换为HTML实体,或解码实体以还原可读文本。

工作原理

将特殊字符转换为HTML实体,或解码实体以还原可读文本。

常见用途

将特殊字符转换为HTML实体,或解码实体以还原可读文本。

使用限制

结果可能因浏览器、网络、输入内容和外部服务而异。本工具仅供参考,不能替代专业诊断或建议。

常见问题
HTML实体编码与解码是什么?
将特殊字符转换为HTML实体,或解码实体以还原可读文本。

相关工具