ghtmx — build HTML with Go and htmx
A templ-compatible template engine that makes htmx a compile-checked language concept: every URL, fragment, and server event in your templates is verified against your Go code at build time.
Route-aware bindings
Every hx-get and hx-post URL resolves against a real Go route at build time — rename a route and the build breaks at every binding site.
Compile-time fragments
fragment blocks render inline in a page and standalone for htmx swaps, byte-identically — no drift between full pages and partial updates.
Typed server events
event declarations generate the only HX-Trigger emitters, with typed payloads shared by handlers and templates.
package main
templ page(name string) {
<!DOCTYPE html>
<html>
<head>@ghtmxgen.HTMXScript()</head>
<body>
<h1>Hello, { name }</h1>
<button hx-get={ home } hx-target="body">reload</button>
</body>
</html>
}ghtmx
A compiled Go template engine where htmx is a first-class, compile-checked language concept — a hard fork of templ that keeps its syntax (see the fork baseline) and adds three things:
- Route-aware bindings —
hx-post={ handlers.CreateUser }andhx-get={ ghtmxgen.GetUser(id) }resolve at build time against your actual Go routes. No hand-written URL strings; renaming a route breaks the build at every binding site. - Compile-time fragments —
fragmentblocks compile to one shared body with an inline entry point for full pages and a standalone entry point for htmx partial updates, byte-identical by construction. - A server-driven event contract —
eventdeclarations generate the only symbols that can emitHX-Trigger, with typed payloads; undeclared events are Go compile errors.
Everything ships in one Go module with a stdlib-only runtime, a build-time compiler with live-reload watch mode, an LSP with route-aware completion, and editor extensions for VS Code, Neovim, and JetBrains.
Start with Getting started, then the
Syntax specification. The
Diagnostics catalogue explains every error the
toolchain can raise, Configuration covers ghtmx.json
and the CLI, and Build targets states what is
supported where — including the WebAssembly guarantee.
Stability (pre-1.0)
ghtmx is pre-1.0: breaking changes to language syntax, generated-code shape, and the runtime API may land between minor versions. Every breaking change carries a changelog entry with a migration note — a build gate enforces the discipline. Pin a version and read the changelog before upgrading.