urls.Anchorize
Returns the given string, sanitized for usage in an HTML id attribute.
Syntax
urls.Anchorize INPUT
Returns
string
Alias
anchorize
The anchorize and urlize functions are similar:
- Use the
anchorizefunction to generate an HTMLidattribute value - Use the
urlizefunction to sanitize a string for usage in a URL
For example:
{{ $s := "A B C" }}
{{ $s | anchorize }} → a-b-c
{{ $s | urlize }} → a-b-c
{{ $s := "a b c" }}
{{ $s | anchorize }} → a-b---c
{{ $s | urlize }} → a-b-c
{{ $s := "< a, b, & c >" }}
{{ $s | anchorize }} → -a-b--c-
{{ $s | urlize }} → a-b-c
{{ $s := "main.go" }}
{{ $s | anchorize }} → maingo
{{ $s | urlize }} → main.go
{{ $s := "Hugö" }}
{{ $s | anchorize }} → hugö
{{ $s | urlize }} → hug%C3%B6The ursl.Anchorize function sanitizes the resulting string per the autoIDType setting in your project configuration.
Last updated:
May 25, 2026
:
content: Wrap relevant description list terms in backticks (911c1c754)
Improve this page