html/template
Webimport "html/template"Implements data-driven templates for generating HTML output safe against code injection.
Example
package main
import (
"html/template"
"os"
)
func main() {
tmpl := template.Must(template.New("page").Parse("<h1>{{.Title}}</h1>"))
tmpl.Execute(os.Stdout, struct{ Title string }{"Hello"})
}Key Types & Functions
TemplateMustNewParseExecuteFuncMapAbout html/template
The html/template package (imported as html/template) belongs to the Web category of Go packages. Implements data-driven templates for generating HTML output safe against code injection.
Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The html/template package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.
When using html/template in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.