Home › htmx › htmx + server-rendered HTML AGENTS.md

htmx + server-rendered HTML AGENTS.md

AGENTS.md for htmx 2 apps with server-rendered templates (any backend), partials, and progressive enhancement.

AGENTS.mdhtmx

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

AGENTS.mdDownload  
# AGENTS.md: htmx 2 hypermedia app

## Principles
- The server returns HTML, not JSON. Each interactive area has a template partial the server can render alone.
- Pages must work without JavaScript first: real `<a href>` and `<form action method>`; htmx attributes enhance them (`hx-boost`, `hx-get`, `hx-post`).
- Check the `HX-Request` header to return a partial vs. the full page from the same route.
- Target precisely: `hx-target` with an id, `hx-swap="outerHTML"` for replacing a component, `hx-swap-oob` for side updates like counters or flash messages.
- Show progress with `hx-indicator`; disable double submits with `hx-disabled-elt="this"`.
- Validation errors re-render the form partial with status 422 and messages next to fields (configure htmx to swap 4xx responses if the project does).
- Redirect after a mutation with the `HX-Redirect` or `HX-Location` response header.
- Small client behavior: htmx events plus a few lines of vanilla JS or Alpine.js. No SPA framework.

## Security
- Escape all output through the template engine; never build HTML strings by hand.
- CSRF token on every non-GET request (via `hx-headers` on `<body>` or a hidden input).

## Don't
- Don't add React/Vue, client-side routing, or JSON endpoints just for htmx.

## Done
Click through the changed flow with JS on and off, then run the backend test suite.

More: all htmx rules · all AGENTS.md rules

Related rules

Browser extension with WXT AGENTS.md

AGENTS.md for cross-browser Manifest V3 extensions built with WXT: entrypoints, messaging, storage, and permissions.

AGENTS.mdChrome extensions

Next.js AGENTS.md

AGENTS.md for Next.js 16 App Router projects: commands, folder layout, data access, auth, and done criteria.

AGENTS.mdNext.js

Nuxt 4 AGENTS.md

AGENTS.md for Nuxt 4 apps: the app/ directory layout, data fetching keys, server routes with validation, and runtime config.

AGENTS.mdVue / Nuxt

SvelteKit AGENTS.md

AGENTS.md for SvelteKit 2 + Svelte 5 (runes) apps with TypeScript.

AGENTS.mdSvelteKit

TypeScript npm library AGENTS.md

AGENTS.md for publishing TypeScript npm packages: ESM exports maps, bundling with tsdown, type checks, and changesets.

AGENTS.mdTypeScript

Vue 3 + Pinia AGENTS.md

AGENTS.md for Vue 3.5 single-page apps on Vite with the Composition API, Pinia, and Vue Router 4.

AGENTS.mdVue / Nuxt

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.