Installation
Requirements
Section titled “Requirements”- Go 1.26+
- templ CLI (install)
- Tailwind CSS 4.x+
- HTMX 2.x (optional, for the
htmxpackage) GOEXPERIMENT=jsonv2environment variable (until Go 1.27 makes it stable)
Install
Section titled “Install”Run this in your project directory:
go get github.com/larsartmann/templ-components@latestIndividual modules (v2.0+)
Section titled “Individual modules (v2.0+)”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:
# 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@latestTailwind CSS Setup
Section titled “Tailwind CSS Setup”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.
go mod vendorThen in your CSS entry point:
@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:
tailwindcss -i app.css -o styles.css --minifyIf your project uses BuildFlow, the tailwind-build provider handles vendoring + scanning automatically.
Verify Installation
Section titled “Verify Installation”go list -m github.com/larsartmann/templ-componentsTroubleshooting
Section titled “Troubleshooting”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:
export GOEXPERIMENT=jsonv2The 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.
Next Steps
Section titled “Next Steps”- Follow the Quick Start for a complete page example
- Learn about Theming to customize colors
- See HTMX Integration for server-rendered interactivity