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

SvelteKit AGENTS.md

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

AGENTS.mdSvelteKit

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

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Next.js App Router (TypeScript) rules

Cursor project rules for Next.js 15 App Router apps with TypeScript, Server Components, and Tailwind.

CursorNext.js

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.