transform.HTMLEscape
Returns the given string, escaping special characters by replacing them with HTML entities.
- Syntax
- transform.HTMLEscape INPUT
- Returns
- string
- Alias
- htmlEscape
Usage
The transform.HTMLEscape function returns the given string, escaping special characters by replacing them with HTML entities. It escapes these five characters:
&→&<→<>→>'→'"→"
When you print the result in an HTML template, Hugo escapes the entities again. To prevent this, pass the result through the safe.HTML function. See safe types for details.
Examples
{{ transform.HTMLEscape "Lilo & Stitch" }} → Lilo & Stitch
{{ transform.HTMLEscape "7 > 6" }} → 7 > 6Comparing the result with and without safe.HTML, showing the raw HTML output:
{{ transform.HTMLEscape "Lilo & Stitch" }} → Lilo &amp; Stitch
{{ transform.HTMLEscape "Lilo & Stitch" | safeHTML }} → Lilo & StitchLast updated:
October 27, 2026
:
content: Standardize print and render usage (c165900b1)
Improve this page