# transform.HTMLEscape
> 返回把特殊字符替换为 HTML 实体后的给定字符串。
- 官方英文原文：https://gohugo.io/functions/transform/htmlescape/
- 本页规范地址：https://hugozh.cn/functions/transform/htmlescape/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：transform.HTMLEscape INPUT
- 返回类型：string
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
`transform.HTMLEscape` 函数通过把五个特殊字符替换为 [HTML 实体][]来转义它们：

- `&` → `&amp;`
- `<` → `&lt;`
- `>` → `&gt;`
- `'` → `&#39;`
- `"` → `&#34;`

例如：

```go-html-template
{{ htmlEscape "Lilo & Stitch" }} → Lilo &amp; Stitch
{{ htmlEscape "7 > 6" }} → 7 &gt; 6
```

[HTML 实体]: https://developer.mozilla.org/en-US/docs/Glossary/Entity

