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:
October 10, 2026
:
theme: Migrate aliases to a redirects data file (b732eba6c)
Improve this page