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 this is a Go module (not an npm 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