HUGO
Menu
GitHub 90265 stars Mastodon

safe.HTML

Returns the given string declared as safe HTML.
Syntax
safe.HTML INPUT
Returns
template.HTML
Alias
safeHTML

Usage

The safe.HTML function returns the given string declared as safe HTML. Use it with a known safe HTML document fragment. Do not use it with HTML from a third party, or with HTML that has unclosed tags or comments. See the Go documentation for details.

Only use this function with content from a trusted source, because Hugo does not check the content for unsafe values. See safe types for an explanation of how Hugo escapes values, and how each safe data type affects escaping.

Examples

{{ safe.HTML "<em>emphasized</em>" }} → <em>emphasized</em>

Comparing the result with and without safe.HTML, showing the raw HTML output:

{{ "<em>emphasized</em>" }} → &lt;em&gt;emphasized&lt;/em&gt;
{{ "<em>emphasized</em>" | safe.HTML }} → <em>emphasized</em>