using-unocss-with-templ
Skill2 starsChanged 8 months agoMITView on GitHub
Integrates UnoCSS atomic CSS engine with Go templ templates for static sites. Use when setting up UnoCSS in templ projects, configuring uno.config.ts for .templ files, using utility classes in templ components, or building static sites with Go and atomic CSS.
- Installs packages
In this repository29 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- building-lit-componentsSkill
- building-static-site-rss-feedsSkill
- building-templ-componentsSkill
- checking-wsh-vrtSkill
- committing-codeSkill
- creating-agent-skillsSkill
- creating-test-casesSkill
- deploying-with-isucon-ansibleSkill
- designing-isucon-architectureSkill
- frontend-designSkill
- operating-isucon-servers-via-sshSkill
- planning-wsh-improvementsSkill
- porting-isucon-rust-to-goSkill
- releasing-zig-with-goreleaserSkill
- running-isucon-as-an-agentSkill
- sharing-sockets-with-so-reuseport-in-zigSkill
- tuning-isucon-linux-and-nginxSkill
- using-go-tool-directiveSkill
- using-grafana-mcpSkill
- winning-isuconSkill
- winning-web-speed-hackathonSkill
- writing-feature-specSkill
- writing-implementation-tasksSkill
- writing-isucon-arch-subagent-tasksSkill
- writing-project-constitutionSkill
- writing-technical-designSkill
- writing-zig-cli-toolsSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 6 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 203
When classes are fully dynamic, use safelist:
- Very specific: line 248
Check file patterns in CLI command match your .templ files
- Very specific: line 249
Verify content.filesystem in config includes .templ
- Distinctive: line 250
Use safelist for fully dynamic class names
- Distinctive: line 254
Ensure CSS file is linked in HTML head
- Distinctive: line 255
Check browser dev tools for CSS loading
- Distinctive: line 256
Verify class names match UnoCSS syntax
- Distinctive: line 260
Run templ and UnoCSS watch in separate terminals or use a process manager:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Using UnoCSS with Templ
Integrate UnoCSS, an instant on-demand atomic CSS engine, with Go's templ templating language to build static sites with utility-first CSS.
Use this skill when setting up UnoCSS for templ projects, configuring CSS extraction from .templ files, or building static sites with Go and atomic CSS.
Quick Start
1. Install Dependencies
# Install templ
go install github.com/a-h/templ/cmd/templ@latest
# Install UnoCSS CLI
npm install -D unocss @unocss/cli2. Create UnoCSS Config
// uno.config.ts
import { defineConfig, presetUno } from "unocss";
export default defineConfig({
presets: [presetUno()],
content: {
filesystem: ["**/*.templ"],
},
});3. Add Package Scripts
{
"scripts": {
"css:build": "unocss \"**/*.templ\" -o static/uno.css",
"css:watch": "unocss \"**/*.templ\" -o static/uno.css --watch"
}
}4. Use Classes in Templ
// components/button.templ
package components
templ Button(text string) {
<button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
{ text }
</button>
}5. Include CSS in Layout
// layouts/base.templ
package layouts
templ Base(title string) {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>{ title }</title>
<link rel="stylesheet" href="/static/uno.css"/>
</head>
<body class="min-h-screen bg-gray-100">
{ children... }
</body>
</html>
}6. Build Process
# Development (parallel)
templ generate --watch &
npm run css:watch &
# Production
templ generate
npm run css:build
go build -o app .Core Concepts
UnoCSS Overview
UnoCSS is an atomic CSS engine that:
- Generates CSS on-demand from utility class usage
- Has no runtime overhead (build-time only)
- Supports multiple presets (Tailwind-compatible, icons, attributify)
- Extracts classes from any file type via CLI
How Extraction Works
UnoCSS CLI scans files for utility class patterns and generates only the CSS needed:
# Scan specific patterns
unocss "components/**/*.templ" "pages/**/*.templ" -o static/uno.css
# With minification
unocss "**/*.templ" -o static/uno.css --minifyTempl Integration
Templ files use standard CSS class syntax:
// Static classes
<div class="flex items-center gap-4">
// Dynamic classes (extracted if static)
<div class={ "p-4", templ.KV("bg-red-500", hasError) }>
// Conditional classes
if isActive {
<span class="text-green-500">Active</span>
} else {
<span class="text-gray-500">Inactive</span>
}CLI Commands
# Basic usage
unocss "**/*.templ" -o static/uno.css
# Watch mode for development
unocss "**/*.templ" -o static/uno.css --watch
# With preflights (reset styles)
unocss "**/*.templ" -o static/uno.css --preflights
# Minified output
unocss "**/*.templ" -o static/uno.css --minify
# Custom config file
unocss "**/*.templ" -o static/uno.css -c uno.config.tsCommon Patterns
Responsive Design
templ Card() {
<div class="p-4 md:p-6 lg:p-8">
<h2 class="text-lg md:text-xl lg:text-2xl">Title</h2>
</div>
}Dark Mode
templ ThemeAwareCard() {
<div class="bg-white dark:bg-gray-800 text-gray-900 dark:text-white">
Content
</div>
}State Variants
templ InteractiveButton() {
<button class="bg-blue-500 hover:bg-blue-600 active:bg-blue-700 focus:ring-2">
Click me
</button>
}Grid Layout
templ ProductGrid(products []Product) {
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
for _, p := range products {
@ProductCard(p)
}
</div>
}Safelist for Dynamic Classes
When classes are fully dynamic, use safelist:
// uno.config.ts
export default defineConfig({
safelist: [
// Always include these
"bg-red-500",
"bg-green-500",
"bg-blue-500",
// Generate ranges
...Array.from({ length: 5 }, (_, i) => `p-${i + 1}`),
],
});Reference Files
- Configuration: See UNO-CONFIG.md
- Development workflow: See WORKFLOW.md
- Presets guide: See PRESETS.md
Project Structure
my-project/
├── components/
│ ├── button.templ
│ └── card.templ
├── layouts/
│ └── base.templ
├── pages/
│ └── home.templ
├── static/
│ └── uno.css # Generated
├── uno.config.ts
├── package.json
├── go.mod
└── main.goTroubleshooting
Classes Not Generated
- Check file patterns in CLI command match your
.templfiles - Verify
content.filesystemin config includes.templ - Use safelist for fully dynamic class names
Classes Not Applied
- Ensure CSS file is linked in HTML head
- Check browser dev tools for CSS loading
- Verify class names match UnoCSS syntax
Watch Mode Issues
Run templ and UnoCSS watch in separate terminals or use a process manager:
# Using npm-run-all
npm install -D npm-run-all{
"scripts": {
"dev": "run-p dev:*",
"dev:templ": "templ generate --watch",
"dev:css": "unocss \"**/*.templ\" -o static/uno.css --watch",
"dev:go": "go run ."
}
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

