Skip to content

Installation

  • Go 1.26+
  • templ CLI (install)
  • Tailwind CSS 4.x+
  • HTMX 2.x (optional, for the htmx package)
  • GOEXPERIMENT=jsonv2 environment variable (until Go 1.27 makes it stable)

Run this in your project directory:

Terminal window
go get github.com/larsartmann/templ-components@latest

Since v2.0, the library is a 5-module workspace (see ADR-0034). You can adopt individual modules without pulling in the full UI library:

Terminal window
# Icons only (pure SVG, no Tailwind dependency):
go get github.com/larsartmann/templ-components/icons@latest
# Error pages only (isolates go-error-family):
go get github.com/larsartmann/templ-components/errorpage@latest
# ECharts adapter only:
go get github.com/larsartmann/templ-components/charts/echarts@latest

Since this is a Go module (not an pnpm package), you need to vendor the dependency so Tailwind can scan the .templ source files for class names.

Terminal window
go mod vendor

Then in your CSS entry point:

app.css
@import "tailwindcss";
/* Scan templ-components for class names */
@source "../vendor/github.com/larsartmann/templ-components";
/* Enable class-based dark mode toggle */
@custom-variant dark (&:where(.dark, .dark *));

Build with the Tailwind CLI:

Terminal window
tailwindcss -i app.css -o styles.css --minify

If your project uses BuildFlow, the tailwind-build provider handles vendoring + scanning automatically.

Terminal window
go list -m github.com/larsartmann/templ-components

build constraints exclude all Go files in .../encoding/json/v2

Section titled “build constraints exclude all Go files in .../encoding/json/v2”

The errorpage module uses encoding/json/v2, which requires the jsonv2 experiment on Go 1.26. Export it before building:

Terminal window
export GOEXPERIMENT=jsonv2

The flag becomes the default when Go 1.27 ships. Until then, put it in your .envrc, flake.nix devShell, or CI environment so every tool picks it up.