Templ is an open-source HTML templating language for Go that compiles templ files into Go code and provides a CLI, language server, and IDE tooling.
What is Templ?
Templ is an open-source HTML templating language for Go, developed by the a-h organization, designed for writing HTML user interfaces directly in Go. It takes templ source files as input and outputs generated Go code that renders HTML, relying on the Go toolchain for compilation and testing. The project is hosted on GitHub, has a package reference on pkg.go.dev, and is actively developed with a dedicated documentation site at templ.guide.
Key Features
- CLI with multiple commands — The
templcommand offersgenerateto compile templates,fmtto format templ and Go code,versionto set version numbers, andlspoperations, as shown in the project's task list. - Language Server Protocol support — The repository includes an
lspcmddirectory and listslanguage-serverandlspamong its topics, indicating built-in LSP capabilities for IDE integration. - htmx compatibility — Templ lists htmx as a topic, confirming that it is designed to work with htmx for server-side rendered interactive web UIs.
- Go-native testing and coverage — The project runs
go test ./..., and itstest-covertask usesgo tool covdatato compute precise test coverage percentages, showing deep integration with the Go toolchain. - Fuzz testing for the parser — Fuzz targets exist for both the main parser and the Go expression parser, executed via
./parser/v2/fuzz.shand./parser/v2/goexpression/fuzz.sh. - Documentation site and npm build pipeline — The
docsdirectory includes a separate npm project that runs a development server (npm run start) and builds the production site (npm run build).
Who is it for?
- Go backend developers who want to write HTML in the same language as their backend, avoiding separate template files.
- Teams building server-rendered apps with htmx who need a type-safe way to generate HTML that works with htmx attributes and fragments.
- Developers who value IDE tooling will benefit from the language server for autocomplete, diagnostics, and formatting while writing templ files.
- Open-source contributors interested in language design, parsers, or Go code generation can build and test templ using its task pipeline.
Use cases
- Web application development: Write reusable HTML components in templ files, run
templ generateto produce Go code, and serve them with any Go HTTP handler. - Formatting and code quality: Use
templ fmtto automatically format all templ and Go files in a project, ensuring consistent style across a team. - Interactive pages with htmx: Combine templ-generated HTML with htmx attributes to create dynamic page updates without a JavaScript framework.
- Benchmarking and performance tuning: Run the benchmark task (
go test ./... -bench=. -benchmem) to measure the performance of templ-generated rendering code.
How does Templ work?
Templ provides a pipeline of CLI commands. Developers write templates in the templ language, run templ generate to produce Go code, and then compile and test that code with standard Go commands. The fmt command normalizes formatting, and the version command handles version strings for releases. This workflow is visible in the project's task definitions, where each step is executed with go run ./cmd/templ ....
FAQ
Does Templ work with htmx?
Yes. The Templ GitHub repository lists htmx among its topics, and the language is designed to complement server-side rendering with htmx for interactive web interfaces.
Is Templ open-source?
Templ is open-source and hosted on GitHub under the a-h organization. It has badges for Go Reference, Go Report Card, and test coverage, and its source code is publicly available under the repository structure.
How do I compile Templ templates?
You run the templ generate command, which is invoked in the project's build and test tasks as go run ./cmd/templ generate -include-version=false. This produces Go code from your template files.
What commands does the Templ CLI include?
The task list shows commands including generate, fmt, version, and LSP-related operations. These are executed through the cmd/templ package and cover compilation, formatting, versioning, and language server functions.
Is there a documentation website?
Yes, user documentation is available at templ.guide. The docs site is maintained in a docs directory with a separate npm project that can be run locally via npm run start.








