Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 13, 2026·3 min de lectura

Templ — HTML Templating Language for Go

A type-safe templating language that lets Go developers write HTML components with full IDE support, hot reload, and compile-time checking.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Templ
Comando de instalación directa
npx -y tokrepo@latest install a07a2e6c-7e50-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

Templ is a strongly-typed HTML templating language designed specifically for Go. It compiles templates into plain Go code, giving you compile-time type safety, IDE autocompletion, and the performance of pre-compiled templates without runtime parsing overhead.

What Templ Does

  • Compiles .templ files into type-safe Go functions
  • Provides full LSP support for autocompletion and error checking in editors
  • Supports hot reload during development via templ generate --watch
  • Integrates naturally with htmx and server-side rendering patterns
  • Enables component composition with Go-native function calls

Architecture Overview

Templ uses a custom parser that reads .templ files containing a mix of Go expressions and HTML markup. The templ CLI generates plain Go source files from these templates. At runtime, generated functions write directly to an io.Writer with zero reflection, achieving performance comparable to hand-written fmt.Fprintf calls.

Self-Hosting & Configuration

  • Install via go install or download a prebuilt binary
  • Add templ generate to your build step or use --watch for development
  • Configure your editor with the templ LSP for syntax highlighting
  • Works with any Go web framework (net/http, Echo, Chi, Fiber)
  • No external runtime dependencies beyond the Go standard library

Key Features

  • Compile-time type checking eliminates runtime template errors
  • IDE support with autocompletion, go-to-definition, and rename refactoring
  • Components are regular Go functions, composable and testable
  • Built-in CSS class management and conditional rendering
  • Automatic HTML escaping prevents XSS by default

Comparison with Similar Tools

  • html/template — runtime parsing with string typing vs compile-time safety
  • Gomponents — pure Go DSL vs HTML-like syntax with better readability
  • Jet — fast runtime templates vs zero-runtime-cost generated code
  • JSX/React — client-side rendering vs server-side with no JavaScript required
  • htmx + Go — complementary; templ generates the HTML that htmx enhances

FAQ

Q: Can I use templ with existing Go web frameworks? A: Yes. Templ components implement io.WriterTo and work with any framework that accepts http.Handler.

Q: How does performance compare to html/template? A: Templ-generated code is significantly faster because templates are compiled to Go at build time with no runtime parsing.

Q: Does templ support hot reload? A: Yes, run templ generate --watch alongside your Go server with air or similar for live reloading.

Q: Is there editor support? A: The official templ LSP works with VS Code, Neovim, and any editor supporting the Language Server Protocol.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados