Fragment payload must be structurally valid for target context (especially table updates via OOB <template><tbody ...>)
Defaults
Use innerHTML swap for list updates
Use outerHTML for full replacement
Anti-Patterns
Do NOT use JSON APIs for HTMX
Do NOT mix with React/Vue
Do NOT manipulate DOM manually with JS
1---2name: htmx-interactions3description: Skill: htmx-interactions4---5# Skill: htmx-interactions67## Type8interactivity910## Purpose1112Enable dynamic UI updates using HTMX without a full SPA framework.1314---1516## When to Use1718Use when adding interactivity to server-rendered applications.1920---2122## Rules2324- Use hx-get, hx-post for interactions25- Always define hx-target26- Use hx-swap to control DOM updates27- Build HTMX URLs with Thymeleaf attributes (for example `th:attr="hx-post=@{/users}"`) so routes stay context-relative28- In controllers, branch full-page vs fragment behavior using `HX-Request` header when endpoint behavior differs29- For HTMX-triggered redirects/navigation, use `HX-Redirect` or `HX-Location` on non-3xx responses (htmx headers are not processed on 3xx)3031---3233## Patterns3435- Replace content dynamically36- Load partials from server37- Submit forms via HTMX38- Keep baseline links/forms functional without HTMX (progressive enhancement)39- For multi-region updates (table row append + form reset), prefer `hx-swap="none"` + out-of-band swaps from server fragments40- For HTMX validation errors, set `HX-Retarget` and `HX-Reswap` headers to place error fragments in the intended container4142---4344## Example4546```html47<button 48 hx-get="/users/list" 49 hx-target="#user-list" 50 hx-swap="innerHTML">51 Load Users52</button>53```5455---5657## Form Example5859```html60<form hx-post="/users" hx-target="#user-list">61 <input name="name" />62 <button type="submit">Save</button>63</form>64```6566---6768## Server Expectation6970* Server returns HTML (NOT JSON)71* Prefer fragments for partial updates72* Fragment payload must be structurally valid for target context (especially table updates via OOB `<template><tbody ...>`)7374---7576## Defaults7778* Use `innerHTML` swap for list updates79* Use `outerHTML` for full replacement8081---8283## Anti-Patterns8485* Do NOT use JSON APIs for HTMX86* Do NOT mix with React/Vue87* Do NOT manipulate DOM manually with JS
Run npx skillmds@latest add carlnaddy/htmx-interactions in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Skill: htmx-interactions It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
CarlNaddy (@carlnaddy) published this skill. Their other Agent Skills are listed on their SkillMD profile.