CLI tool
a-h/templ avatar
a-h/templ

templ: compiling HTML components into Go, and the generate step every project inherits

A language for writing HTML user interfaces in Go.

10,615 stars385 forksGoMIT

At a glance

What is it?
a-h/templ is an MIT-licensed language for writing HTML user interfaces in Go, shipped as a command line tool with generate, fmt and an LSP. It is mature in tooling but still versioned 0.3.x, and its build model puts a code generation step and a recent Go toolchain in front of every project that adopts it.
Who is it for?
templ fits Go teams who want HTML components checked by the Go compiler and are comfortable adding a generate step and committing its output; the examples for chi, echo, gin, gofiber, htmx fragments and streaming show where it is meant to sit.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 9 days ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • a-h/templ10,615 ★ · +47
Star history
Repository2026-10-072026-11-22
a-h/templ10.6k10.6k

47 Stars in the last 46 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

A templating language that becomes Go code through templ generate

templ describes itself as a language for writing HTML user interfaces in Go, built around good developer tooling. The core of that tooling is a single binary built from cmd/templ, with subcommands visible throughout the repository tasks: generate, fmt and version. Instead of parsing templates at runtime, you write templ files and run generate to turn them into Go source that compiles with the rest of your program. The repository layout follows that split: parser/ and generator/ handle the language, while the root package holds the runtime that generated code calls, with files such as handler.go, fragment.go, flush.go, join.go, once.go and url.go.

The consequence is that a templ project has a build step a plain html/template project does not. Every change to a template has to be regenerated before go build sees it, and generated code ends up in your tree. The repository treats this seriously enough to have an ensure-generated task, covered below. User documentation, including the syntax reference, lives at templ.guide rather than in the README, which is written for contributors.

Generated files are committed, and CI fails if they drift

The ensure-generated task checks that templ files have been generated with the local version of templ and that those generated files have been added to git. It requires the generate task first and then runs:

sh
git diff --exit-code

Generation inside the repository itself runs with a flag that keeps output stable:

sh
go run ./cmd/templ generate -include-version=false

This is a pattern worth copying in your own project. If teammates run different templ versions, regenerated files can differ even when no template changed, and a git diff check in CI catches that before it reaches review. The cost is discipline: everyone, including CI, has to use the same templ version, and pull requests carry generated Go alongside the templ source. Teams that dislike committed generated code should know up front that templ's own workflow assumes it.

Building from source leaves an old binary path behind

The README's install route is for contributors building from a checkout. The install-snapshot task reads:

sh
# Remove templ from the non-standard ~/bin/templ path
# that this command previously used.
rm -f ~/bin/templ
# Clear LSP logs.
rm -f cmd/templ/lspcmd/*.txt
# Update version.
version set
# Install to $GOPATH/bin or $HOME/go/bin
cd cmd/templ && go install

Two details matter. Earlier versions of this task installed to ~/bin/templ, so anyone who used it before may have a stale binary there that shadows the new one in $GOPATH/bin or $HOME/go/bin, depending on PATH order. If templ version reports something unexpected after upgrading, that old path is the first place to look. Second, the LSP writes log files into cmd/templ/lspcmd as .txt files, which this task clears. The version set step depends on a separate version tool that reads the .version and .version-template files at the repository root; it is not part of the Go toolchain, so a bare go build without it produces a binary whose version string was not refreshed.

A Go 1.26.0 floor and a parser dependency pinned to a commit

go.mod declares go 1.26.0. Projects that build templ from source, or that import its runtime package, need a toolchain at least that new. Teams that lag a Go release or two behind will hit this before anything else.

The parser rests on github.com/a-h/parse at the pseudo-version v0.0.0-20261027111828-db2689052003, a commit from the same author rather than a tagged release. A commented-out replace directive pointing at a local path on the maintainer's machine sits at the bottom of go.mod, which shows the two repositories are developed together. Other direct dependencies include fsnotify for file watching, cli/browser, rs/cors, andybalholm/brotli, cenkalti/backoff/v4, and golang.org/x/tools, x/net, x/mod and x/sync. For a consumer this list matters mostly for vulnerability scanning: the repository runs govulncheck ./... as its own vulncheck task, and you can run the same command on your module after adding templ.

Still v0.3.x after many releases

Recent tags are v0.3.1020 on 2026-05-10, v0.3.1070 on 2026-10-04 and v0.3.1100 on 2026-10-26, and the last push to main was on 2026-10-30. The project is clearly active, but the major version is still zero. Under Go module rules that means no compatibility promise between minor releases, so pin the exact version in go.mod and in whatever installs the templ binary in CI, and read the release notes before bumping.

Releases are built with goreleaser, configured in .goreleaser.yaml, and a local snapshot build uses:

sh
goreleaser build --snapshot --clean

A cosign.pub public key also sits at the repository root. Publishing a new version is a single tagging step, version push --prefix="v", which triggers the release process on GitHub. The practical upshot is that releases come often and cheaply, which is good for fixes and a reason to keep generated code and binary versions in lockstep.

JavaScript handling is fuzzed in modules kept out of your dependency graph

templ deals with more than HTML. The root package has js.go, jsonscript.go, jsonstring.go, scripttemplate.go and a safehtml/ directory, there is an internal/jstokenizer, and the examples include content-security-policy and typescript. Getting script and attribute contexts wrong is where template engines leak injection bugs, and templ fuzzes these paths. The test-fuzz task runs four scripts, each for FUZZTIME, which defaults to 120 seconds:

sh
./parser/v2/fuzz.sh
./parser/v2/goexpression/fuzz.sh
./runtime/fuzzing/fuzz.sh
./internal/jstokenizer/fuzzing/fuzz.sh

The runtime and JavaScript tokenizer fuzz tests live in separate modules on purpose, so that their JavaScript engine and parser dependencies do not become dependencies of templ. The trade-off is that go test ./... in the root module does not run them; only the parser fuzz corpora run in the normal test and test-cover tasks. Contributors who touch the runtime or tokenizer must remember the test-fuzz-corpus task as well.

templ fmt calls out to prettier

Formatting is part of the toolchain: the fmt task runs gofmt -s -w . followed by go run ./cmd/templ fmt . to format both Go and templ code. The benchmark-fmt task notes that its timings include the time taken by prettier, which tells you templ fmt hands some content to prettier. There is also a .templignore_fmt file at the root for excluding paths from formatting.

The consequence is that formatting speed and output depend partly on an external JavaScript formatter. If templ fmt is slow on a large project, or produces different output on two machines, prettier is a candidate to check. Contributors also need more than Go for the full task list: gotestsum for test-cover-watch, golangci-lint for the lint task that mirrors CI, go tool covd for combined coverage, goreleaser for snapshots, npm for the docs site in docs/, and a flake.nix is provided for those who use Nix to supply them.

Editorial conclusion

templ fits Go teams who want HTML components checked by the Go compiler and are comfortable adding a generate step and committing its output; the examples for chi, echo, gin, gofiber, htmx fragments and streaming show where it is meant to sit. It is a weaker fit for projects stuck on an older Go toolchain or teams that need a 1.0 compatibility promise, since releases are still numbered v0.3.x. Before adopting it, check that your Go version satisfies the go 1.26.0 line in go.mod and read templ.guide for the user-facing install and syntax, which the repository README leaves to that site.

Frequently asked questions

What is a good golang templ alternative, and how does templ differ?

templ is a compiled language: templ generate turns templ files into Go code, and the project adds templ fmt and an LSP for editors. Weigh any alternative against that build step and the Go 1.26.0 requirement in templ's go.mod.

Which web frameworks does templ show integration examples for?

The templ repository includes examples for chi, echo, gin, gofiber and go-echarts, plus htmx fragments, streaming, suspense, a static generator and a React integration.

How do I install templ from source?

From a checkout of a-h/templ, run version set and then cd cmd/templ && go install, which places the binary in $GOPATH/bin or $HOME/go/bin. Remove any old ~/bin/templ first, since earlier versions of that task installed there.

Official sources

  1. a-h/templ on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/a-h-templ.svg)](https://hysenlabs.com/projects/a-h-templ)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/a-h-templ.svg)](https://hysenlabs.com/projects/a-h-templ)

Was this useful?