templ-components
Server-rendered UI components for Go. Built with templ, HTMX, and Tailwind CSS v4.
# Layout Primitives
Container (width variants)
Centered max-width wrapper with responsive padding. Replaces the repeated max-w-Nxl mx-auto px-4 sm:px-6 lg:px-8 snippet.
Stack (vertical rhythm)
Typed gap enum replaces repeated space-y-N strings. 1D vertical (flex, not grid).
Stack item 1
Stack item 2
Stack item 3 — each child gets consistent spacing
Split (content + aside)
2-column grid for article+sidebar / detail+metadata. RTL-aware logical positioning (Start/End). Stacks below md.
Main content (2/3)
Article body, detail view, or primary content lives here.
AppShell (sidebar + header + main)
The #1 admin dashboard pattern. Uses minmax(0,1fr) to prevent grid blowout from wide tables. Sidebar hidden on mobile (use MobileNav slot for drawer).
Footer (multi-column grid)
Backward-compatible extension: Columns empty = legacy single-row. Non-empty = responsive multi-column grid with optional brand + BottomBar.
# Cards
Standard Card
With title, subtitle, and body
This is a standard card with header and content.
SimpleCard — no header, just content.
display.Card(display.CardProps{Title: "Users", Subtitle: "Manage your team"}) {
<p>Card content</p>
}# Stat Cards
# Badges
# Buttons
display.Button(display.ButtonProps{Text: "Save", Variant: display.ButtonPrimary})# Avatars
# Modal (native dialog)
@display.Modal(display.ModalProps{Title: "Confirm", Size: display.ModalSizeMD}) {
<p>Are you sure?</p>
}# Drawer (native dialog)
# Dropdown
# Tooltip
# Popover
Popover content
Any content can go here.
# Accordion (native details)
What is templ-components?
How do I install it?
Is it production-ready?
# Tabs
# Tabs (Pills variant)
# Table
| Name ↑ | Role | |
|---|---|---|
| Alice Smith | alice@example.com | Admin |
| Bob Jones | bob@example.com | User |
display.Table(display.TableProps{
Headers: []string{"Name", "Email", "Role"},
Rows: []display.TableRow{
display.SimpleTableRow("Alice", "alice@example.com", "Admin"),
},
Striped: true,
Hover: true,
})# Table in Card (Flush + Compact)
Recent Users
| Name | Status | |
|---|---|---|
| Alice Smith | alice@example.com | Active |
| Bob Jones | bob@example.com | Invited |
# DataTable (sort + pagination)
# PageHeader
User Settings
Manage your account preferences and security options
# SectionHeading + DateRange
Experience
SectionHeading — configurable h1–h6 level, alignment, subtitle
@display.DateRange(display.DateRangeProps{
Start: &start, // End nil renders "Present"
Layout: display.DateFormatJan2_2006,
})# Definition List
- User ID
- usr_01JXEXAMPLE
- admin@example.com
- Plan
- Enterprise
# Definition Grid
- CPU
- 42%
- Memory
- 8.2 GB
- Disk
- 156 GB
- Uptime
- 99.9%
- Requests
- 1.2K/s
- Latency
- 12ms
# Grid + Container Query Grid
- Normal grid
- 42
- Responsive
- 12ms
- To viewport
- 99.9%
Container-responsive (resize this box):
- Requests/s
- 42
- Latency
- 12ms
- Uptime
- 99.9%
display.Grid(display.GridProps{Cols: display.GridCols3, Gap: display.GridGapLG}) {
for _, u := range users {
@display.Card(display.CardProps{Title: u.Name}) { <p>{ u.Email }</p> }
}
}# Fluid Typography (container query units)
Container-aware metric
Revenue scales with this card's width:
$4.2M
Heading in a narrow container
Text shrinks smoothly as the container narrows via cqi units.
# Empty States
No data to display.
# CopyButton
# RelativeTime
# CountBadge
# ListNote
# Image
# HoverCard
Hover details
Shows on hover or focus.
Right-click the area below:
# Carousel
# Sparklines & Bar Charts
Message Trend
Top Channels
# SVG Charts (Line, Pie, Area)
Revenue Trend
Revenue vs Expenses
Active Users
Traffic Sources
Storage Usage
# External Links
# Collapsible Sections
Advanced Settings
These settings are open by default. Users can collapse this section to focus on the overview.
Debug Information
Version: v1.9.0 Build: 2026-08-29T08:14:45Z
# Heatmap
Weekly Activity Heatmap
| 00:00 | 04:00 | 08:00 | 12:00 | 16:00 | 20:00 | 24:00 | |
|---|---|---|---|---|---|---|---|
| Sun | · | ||||||
| Mon | · | ||||||
| Tue | |||||||
| Wed | · | ||||||
| Thu | · | ||||||
| Fri | |||||||
| Sat |
# Alerts
Success
Operation completed.
Error
Something went wrong.
Warning
Check your input.
Info
Here is some information.
feedback.Alert(feedback.AlertProps{Title: "Saved", Message: "Changes saved.", Type: feedback.FeedbackSuccess})# Toast (auto-generated ID, auto-dismiss)
Toasts render into ToastContainer. Each auto-dismisses after 5s.
feedback.Toast(feedback.ToastProps{Message: "Saved!", Type: feedback.FeedbackSuccess, Duration: 5000})# Inline Feedback
# Spinners
# Progress Bars
# CircularProgress
md + label
sm
lg + custom color
# LoadingOverlay
Full-screen overlay for page transitions — pinned to this frame for the demo via a Class override:
Loading workspace...
62%
# Step Indicator
# Skeletons
# Skeleton Card Grid
# Form Controls
Tell us about yourself.
- Germany
- Austria
- Switzerland
- United States
forms.Input(forms.InputProps{Name: "email", Type: forms.InputEmail, Label: "Email"})# Calendar
# ValidationSummary
# Inline Form (Filter Bar)
Filter results appear here (change the Sort dropdown — it auto-submits via HTMX).
Click to fetch the next batch from /api/items — the button replaces itself with the response:
Item 001
Loaded from the server via HTMX.
Item 002
Loaded from the server via HTMX.
hx-trigger="revealed" — fires as soon as the button scrolls into view:
Item 003
Loaded from the server via HTMX.
Item 004
Loaded from the server via HTMX.
# HTMX LoadingIndicator
Global HTMX loading overlay (shows during any htmx request — try any button below):
# HTMX InlineLoadingOverlay
Per-target loading indicator (shown via hx-indicator):
# HTMX LoadingButton
Click — the button swaps to its loading state during the request:
# HTMX ConfirmDelete
Deletes the item below via HTMX after a confirmation dialog:
item-123
Delete me — the row is replaced by the server response.
# HTMX CSRFToken
Renders a hidden CSRF input field:
# HTMX SwapOOB
Out-of-band swap element (processed by HTMX after a response):
# HTMX GlobalErrorHandling
Wires up htmx:responseError and htmx:beforeOnError events:
# HTMX ViewTransitions
Enables native View Transitions on HTMX swaps — pages cross-fade instead of hard-cutting, with graceful degradation in browsers without support.
htmx.ViewTransitions(htmx.ViewTransitionsProps{Global: true, Nonce: nonce})# HTMX PolledRegion
Auto-refreshing region polling /api/demo-stats every 5s (stops after 3 ticks):
Requests served: 48210
Updated 08:14:45 UTC
# Datastar SDKScript
Injects the Datastar runtime as an ES module. Load once per page:
# Datastar LiveRegion
SSE-powered region that auto-connects on page load and self-heals across server restarts (retry: 'always'). The server pushes datastar-patch-elements events to patch the content in real-time (no polling):
Waiting for SSE stream...
# Datastar Indicator
Shows/hides based on a Datastar indicator signal. Place data-indicator:fetching on any element that triggers a backend action:
# Datastar Action Expressions
Typed helpers for building Datastar action expressions:
datastar.Get("/api/search") // @get('/api/search')
datastar.Post("/api/save") // @post('/api/save')
datastar.Delete("/api/items/1") // @delete('/api/items/1')# Datastar SSE Error Handling
Global listener for Datastar stream failures (datastar-fetch events with type error or retries-failed) that surfaces them as accessible toasts — the Datastar counterpart to HTMX GlobalErrorHandling:
@feedback.ToastContainer("")
@datastar.SSEErrorHandling(datastar.DefaultSSEErrorHandlingConfig())HTMX vs Datastar
Both work side-by-side. HTMX uses hx-* attributes for hypermedia exchanges. Datastar uses data-* attributes for SSE streaming and reactive signals.
Use HTMX for request-response (forms, navigation, CRUD). Use Datastar for real-time push (dashboards, live feeds, collaborative editing).
# ECharts SDK + Chart (opt-in module)
charts/echarts is a separate opt-in module: it wraps go-echarts RenderSnippet() output in a CSP-safe container and bridges dark mode — toggle the theme and watch the chart re-theme.
import echarts "github.com/larsartmann/templ-components/charts/echarts"
@echarts.SDKScript(echarts.DefaultSDKScriptProps())
@echarts.EChart(echarts.EChartsProps{
Element: snippet.Element, // from go-echarts RenderSnippet()
Script: snippet.Script,
Nonce: nonce,
})# NotFound404
# ErrorPage
The resource was not found
Suggested fix: Check the URL or return to the homepage.
# ErrorAlert (by family)
Invalid Input
rejectionThe email address format is invalid.
Enter a valid email address.
Version Conflict
conflictSomeone else modified this resource.
Refresh and try again.
Temporary Error
transientA temporary error occurred.
Wait a moment and retry.
Data Corrupted
corruptionConfiguration file is unreadable.
Service Unavailable
infrastructureThe service is currently down.
# ErrorDetail (with context + cause chain)
data.parse_failedcorruptionParse Failed
config.yaml contains invalid syntax at line 42.
Suggested fix: Check the YAML syntax.
| file | config.yaml |
|---|---|
| line | 42 |
db.timeouttransientDatabase Timeout
Query took too long.
Caused by
# All Icons (102)
Search the icon library by name. Click an icon to copy its Go constant name.
# Recipes & Full Pages
Users list
Server-driven DataTable with sorting + pagination round-trips.
Forms page
Complete form with validation states and HTMX filter bar.
Dashboard
recipes.Dashboard — stat cards + charts composition.
Settings
recipes.SettingsLayout — aside nav + section cards.
Login card
recipes.LoginCard — centered sign-in card.
Auth layout
recipes.AuthLayout — split-screen branding + auth card.