Guide · Open source
How to use templ: install, generate and write Go HTML components
Updated · written with AI from the project's own documentation and checked against our catalogue data
templ is an open-source language for writing HTML user interfaces in Go. You write templates in a dedicated .templ format, and templ generates Go code from them that renders HTML. This guide explains how to get the project building from source, how to run templ generate, and where the developer tooling fits in, so you can decide whether it suits your Go web project.
Quick start
- 1Check prerequisites. Make sure Go and Git are installed on your machine.
- 2Clone the repository. Run git clone https://github.com/a-h/templ to get the source.
- 3Move into the project. Change into the cloned templ directory so the local commands work.
- 4Generate templ files. Run go run ./cmd/templ generate -include-version=false to generate Go code from your .templ files.
- 5Run the tests. Run go test ./... after generating to confirm the project works.
- 6Read the user documentation. Visit https://templ.guide for the full user guide, including editor setup.
What templ is and who it is for
templ is a language for writing HTML user interfaces in Go. Instead of building HTML as strings, you write templates in .templ files and templ generates Go code from them that renders the HTML.
The project is aimed at Go developers building server-side rendered web pages, and at teams using Go with htmx or similar HTML-first approaches. It is not a fit if you do not use Go, if your main UI layer is a JavaScript-heavy front end framework, or if you have no Go experience yet.
What you need before you start
The install method described in the README is clone-and-build. The listed prerequisites are Go and Git.
You should be comfortable with basic Go projects before using templ, because templ generates Go code and the generated files are part of your Go code.
- Go
- Git
Clone the templ repository
Start by cloning the repository from GitHub. The README gives this command for the source code.
git clone https://github.com/a-h/templGenerate templ files with the local version
Inside the cloned repository, the README shows how to generate templ files using the local version of the tool. The -include-version=false flag is part of that command.
The generate task in the project runs the same command, so you can use it as the standard way to regenerate Go code from your .templ files.
go run ./cmd/templ generate -include-version=falseBuild and test the project
The README lists several tasks for working on templ itself. The build task builds a local version from the cmd/templ directory. The test task regenerates files and runs the Go tests.
If you only want to check that the project works, the test command is the most direct option. The README also lists lint, fmt and vulncheck tasks for code quality.
- build: builds a local version from cmd/templ
- test: regenerates templ files and runs go test ./...
- fmt: formats Go and templ code
- lint: runs golangci-lint, the same lint operations as CI
- vulncheck: checks dependencies with govulncheck
go run ./cmd/templ generate -include-version=false
go test ./...Use the developer tooling
The README highlights developer tooling, including IDE support through a language server. The source does not describe the setup steps for your editor, so check the user documentation at https://templ.guide for editor configuration.
The docs site is run from the docs directory with npm, using the start and build scripts listed in the README.
- Documentation: https://templ.guide
- Docs development server: npm run start in the docs directory
- Production docs build: npm run build in the docs directory
npm run startWhat people use it for
- Rendering server-side HTML pages in a Go web application
- Building typed HTML components in Go instead of string templates
- Pairing Go-rendered HTML with htmx for interactive pages
- Working on templ itself by running its build, test and lint tasks
Frequently asked questions
Is templ free to use?
templ is licensed under the MIT licence, as listed on the project page. Check the LICENSE file in the repository for the full terms.
What do I need to install templ?
The README's install method is clone-and-build, and the prerequisites are Go and Git. It gives the git clone command and the go run ./cmd/templ generate command.
Do I need to know Go to use templ?
Yes. templ is specifically for Go code, and beginners with no Go experience would need to learn Go first.
Does templ work with htmx?
The project is aimed at teams using Go with htmx or similar HTML-first approaches. The source does not describe htmx integration in detail.
What are the alternatives to templ?
Comparable projects listed are html/template, gomponents, and templ-like Go component libraries such as gotempl. html/template is part of Go's standard library, so it needs no extra dependency.
Does templ have editor support?
The README highlights IDE support through a language server. Setup details for your editor are in the user documentation at https://templ.guide.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
templ suits Go developers who render HTML on the server and want typed components rather than string templates, especially with htmx. If you do not use Go, want a JavaScript-heavy front end as your main UI, or are new to Go, pick a different tool or learn Go first.
Install options & downloads