Button
The most-used component. Supports variants, sizes, loading states, icon-only mode, and full HTMX passthrough via Attrs.
Variants
Sizes
With HTMX
Pass any hx-* attribute via the Attrs field.
handler.go
func (h *Handler) Submit(w http.ResponseWriter, r *http.Request) {
// Process...
templ.Handler(components.SuccessToast()).ServeHTTP(w, r)
}page.templ
@button.Button(button.Props{
Variant: button.VariantPrimary,
Type: "submit",
Attrs: templ.Attributes{
"hx-post": "/api/submit",
"hx-target": "#result",
"hx-swap": "outerHTML",
"hx-indicator": "#spinner",
},
}) {
Save changes
}Disabled & Loading
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| Variant | Variant | VariantPrimary | Visual style: primary, secondary, outline, ghost, destructive, link |
| Size | Size | SizeMD | Button height and padding: xs, sm, md, lg, xl |
| Type | string | "button" | HTML button type: "button", "submit", or "reset" |
| Disabled | bool | false | Disables click interaction and applies opacity-50 |
| Class | string | "" | Extra Tailwind classes merged onto the button |
| Attrs | templ.Attributes | nil | Spread any HTML attribute: hx-*, data-*, aria-*, @click, etc. |