htmx-interaction-patterns
Build dynamic web interfaces with htmx using hypermedia-driven patterns for partial page updates, lazy loading, infinite scroll, and server-sent events without writing JavaScript. Triggers on htmx usage, hypermedia architecture, or progressive enhancement requests.
Best use case
htmx-interaction-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Build dynamic web interfaces with htmx using hypermedia-driven patterns for partial page updates, lazy loading, infinite scroll, and server-sent events without writing JavaScript. Triggers on htmx usage, hypermedia architecture, or progressive enhancement requests.
Teams using htmx-interaction-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/htmx-interaction-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How htmx-interaction-patterns Compares
| Feature / Agent | htmx-interaction-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Build dynamic web interfaces with htmx using hypermedia-driven patterns for partial page updates, lazy loading, infinite scroll, and server-sent events without writing JavaScript. Triggers on htmx usage, hypermedia architecture, or progressive enhancement requests.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# htmx Interaction Patterns
Build dynamic interfaces with HTML-over-the-wire — server renders HTML fragments, htmx swaps them in.
## Core Concepts
htmx extends HTML with attributes that make AJAX requests and swap content — no JavaScript required.
```html
<!-- Click button → GET /items → replace #item-list content -->
<button hx-get="/items" hx-target="#item-list" hx-swap="innerHTML">
Load Items
</button>
<div id="item-list"></div>
```
### Key Attributes
| Attribute | Purpose | Example |
|-----------|---------|---------|
| `hx-get` | GET request | `hx-get="/api/items"` |
| `hx-post` | POST request | `hx-post="/api/items"` |
| `hx-put` | PUT request | `hx-put="/api/items/1"` |
| `hx-delete` | DELETE request | `hx-delete="/api/items/1"` |
| `hx-target` | Where to put response | `hx-target="#results"` |
| `hx-swap` | How to insert | `hx-swap="outerHTML"` |
| `hx-trigger` | When to fire | `hx-trigger="click"` |
| `hx-indicator` | Loading indicator | `hx-indicator="#spinner"` |
### Swap Strategies
| Strategy | Behavior |
|----------|----------|
| `innerHTML` | Replace children (default) |
| `outerHTML` | Replace entire target element |
| `afterbegin` | Insert as first child |
| `beforeend` | Insert as last child |
| `beforebegin` | Insert before target |
| `afterend` | Insert after target |
| `delete` | Remove target |
| `none` | No DOM update |
## Common Patterns
### Search with Debounce
```html
<input type="search" name="q"
hx-get="/search"
hx-trigger="input changed delay:300ms"
hx-target="#results"
hx-indicator="#search-spinner"
placeholder="Search skills...">
<span id="search-spinner" class="htmx-indicator">Searching...</span>
<div id="results"></div>
```
Server returns an HTML fragment:
```python
@app.get("/search")
async def search(q: str = ""):
results = search_skills(q)
return HTMLResponse(render_results(results))
```
### Inline Editing
```html
<!-- View mode -->
<div id="skill-42" hx-get="/skills/42/edit" hx-trigger="dblclick" hx-swap="outerHTML">
<h3>testing-patterns</h3>
<p>Write effective tests across the stack...</p>
</div>
<!-- Edit mode (returned by server) -->
<form id="skill-42" hx-put="/skills/42" hx-swap="outerHTML">
<input name="name" value="testing-patterns">
<textarea name="description">Write effective tests...</textarea>
<button type="submit">Save</button>
<button hx-get="/skills/42" hx-swap="outerHTML">Cancel</button>
</form>
```
### Infinite Scroll
```html
<div id="item-list">
<!-- Items rendered here -->
<div hx-get="/items?page=2"
hx-trigger="revealed"
hx-swap="outerHTML">
Loading more...
</div>
</div>
```
Server returns items + next trigger:
```html
<div class="item">Item 11</div>
<div class="item">Item 12</div>
<!-- Next page trigger -->
<div hx-get="/items?page=3" hx-trigger="revealed" hx-swap="outerHTML">
Loading more...
</div>
```
### Lazy Loading
```html
<div hx-get="/dashboard/metrics" hx-trigger="load" hx-swap="innerHTML">
<div class="skeleton-loader"></div>
</div>
```
### Active Search with URL State
```html
<input type="search" name="q"
hx-get="/search"
hx-trigger="input changed delay:300ms"
hx-target="#results"
hx-push-url="true">
```
### Confirmation Dialogs
```html
<button hx-delete="/items/42"
hx-confirm="Delete this item?"
hx-target="#item-42"
hx-swap="outerHTML swap:500ms">
Delete
</button>
```
### Server-Sent Events
```html
<div hx-ext="sse" sse-connect="/events" sse-swap="message">
Waiting for updates...
</div>
```
```python
from sse_starlette.sse import EventSourceResponse
@app.get("/events")
async def events():
async def generate():
while True:
data = await get_update()
yield {"data": render_update(data)}
return EventSourceResponse(generate())
```
## Server-Side Patterns
### Partial vs Full Responses
```python
@app.get("/items")
async def list_items(request: Request):
items = await get_items()
if "HX-Request" in request.headers:
# htmx request: return fragment
return HTMLResponse(render_items_fragment(items))
else:
# Normal request: return full page
return HTMLResponse(render_full_page(items))
```
### Response Headers
```python
from starlette.responses import HTMLResponse
@app.post("/items")
async def create_item(request: Request):
item = await save_item(request)
response = HTMLResponse(render_item(item))
response.headers["HX-Trigger"] = "itemCreated" # Client-side event
response.headers["HX-Retarget"] = "#item-list"
response.headers["HX-Reswap"] = "afterbegin"
return response
```
### OOB (Out-of-Band) Swaps
Update multiple elements from one response:
```html
<!-- Primary swap -->
<div id="item-42">Updated item content</div>
<!-- OOB: also update the counter -->
<span id="item-count" hx-swap-oob="true">43 items</span>
```
## CSS Integration
```css
/* Loading indicator */
.htmx-indicator { opacity: 0; transition: opacity 200ms; }
.htmx-request .htmx-indicator { opacity: 1; }
/* Settling animation */
.htmx-settling { opacity: 0; }
.htmx-settled { opacity: 1; transition: opacity 300ms; }
/* Added items */
.htmx-added { opacity: 0; }
.htmx-settled.htmx-added { opacity: 1; transition: opacity 300ms; }
```
## Anti-Patterns
- **Returning JSON from htmx endpoints** — Always return rendered HTML fragments
- **Large page replacements** — Return small, targeted fragments
- **No loading indicators** — Always show feedback during requests
- **Ignoring non-htmx requests** — Support full-page loads for bookmarkability
- **Client-side state management** — Keep state on the server; let HTML be the stateRelated Skills
webhook-integration-patterns
Designs reliable webhook systems with proper delivery guarantees, retry logic, signature verification, and idempotent processing for event-driven integrations.
vector-search-patterns
Implement vector similarity search with embedding generation, index selection, and hybrid retrieval strategies. Covers ChromaDB, pgvector, FAISS, and RAG pipeline design. Triggers on vector search, embeddings, semantic search, or RAG architecture requests.
testing-patterns
Write effective tests across the stack—unit, integration, E2E, and visual regression. Covers testing philosophy, framework selection, mocking strategies, and CI integration. Triggers on testing, test coverage, TDD, or quality assurance requests.
session-lifecycle-patterns
Manage AI agent session lifecycles with structured phases (FRAME, SHAPE, BUILD, PROVE), context preservation across sessions, handoff protocols, and session metadata tracking. Triggers on session management, agent lifecycle, or multi-session workflow requests.
responsive-design-patterns
Mobile-first responsive design patterns with breakpoints, fluid layouts, and adaptive components
resilience-patterns
Build fault-tolerant systems with circuit breakers, retries with backoff, bulkheads, timeouts, and graceful degradation. Covers distributed system failure modes and recovery strategies. Triggers on reliability engineering, fault tolerance, or distributed system resilience requests.
redis-patterns
Use Redis effectively for caching, pub/sub messaging, rate limiting, distributed locks, and session storage. Covers data structure selection, expiration strategies, and cluster patterns. Triggers on Redis usage, caching architecture, or pub/sub messaging requests.
realtime-websocket-patterns
Implement real-time features with WebSockets, Server-Sent Events, and long polling. Covers connection management, room-based messaging, presence tracking, and scaling strategies. Triggers on WebSocket implementation, real-time communication, or live update feature requests.
react-three-fiber-patterns
Build interactive 3D experiences in React using react-three-fiber (R3F), drei helpers, and shader integration. Covers scene composition, performance optimization, and animation patterns. Triggers on R3F development, React + Three.js, or declarative 3D scene requests.
python-packaging-patterns
Structure Python projects for distribution with pyproject.toml, src layouts, dependency management, and publishing workflows. Covers packaging tools (hatch, setuptools, flit, poetry), versioning strategies, and editable installs. Triggers on Python project setup, packaging configuration, or dependency management requests.
prompt-engineering-patterns
Design effective prompts for LLM agents with structured input/output formats, chain-of-thought reasoning, few-shot examples, and system prompt architecture. Covers Claude-specific patterns and multi-turn conversation design. Triggers on prompt design, LLM interaction patterns, or system prompt architecture requests.
postgres-advanced-patterns
Advanced PostgreSQL patterns for performance optimization, complex queries, indexing strategies, and database design