htmx

A set of coding rules for htmx, a web tool that lets HTML trigger server requests and update parts of a page. It keeps the server responsible for returning HTML rather than JSON data.

In plain words
What is it for?
Use it when building htmx pages or endpoints, especially forms, navigation, loading states, validation, and destructive actions.
Why use it?
It gives developers consistent rules for page updates, loading feedback, browser history, redirects, and form errors. This reduces scattered browser-side code and unclear request behavior.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nedcodes-ok/cursorrules-collection/htmx
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection
Per session 529 This file is loaded in full into every session.
When invoked 529 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00529 $0.00529
Opus 5 $0.00264 $0.00264
Sonnet 5 $0.00106 $0.00106
Haiku 4.5 $0.00053 $0.00053

Measured yesterday against content hash eee419fb37ef, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

htmx scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules-mdc/frameworks/htmx.mdc · 47 lines

How it starts

The opening of the file, as written. The whole thing — 47 lines — stays where its author put it; the contents beside it link to each section on GitHub.

htmx Cursor Rules

You are an expert htmx developer. Follow these rules:

Core Principles

  • Server returns HTML fragments, not JSON. Every endpoint returns renderable markup
  • Progressive enhancement: pages work without JavaScript first, htmx enhances
  • Hypermedia as the engine of application state — URLs and links drive navigation
  • Prefer hx-get/hx-post over fetch/XMLHttpRequest. No client-side state management

Attributes

  • Always set hx-target to scope updates. Never rely on default (innerHTML of triggering element)
  • Use hx-swap="outerHTML" for replacing elements, "innerHTML" for updating contents
  • hx-indicator for loading states on every network request. Users need feedback
  • hx-push-url="true" on navigation requests to maintain browser history
  • hx-confirm for destructive actions (delete, reset)

Server Responses

  • Return 200 with HTML fragment for success. Use HX-Trigger response header for events
  • Return 422 with form HTML (including errors) for validation failures — htmx swaps it in
  • Use HX-Redirect header for server-side redirects, not 301/302
  • Return 204 No Content to do nothing. Return empty string with HX-Trigger for event-only responses
  • Use HX-Retarget and HX-Reswap headers to override client-side targeting from the server

Patterns

  • Inline editing: hx-get to fetch edit form, hx-put to save, swap back to display view
  • Infinite scroll: hx-get with hx-trigger="revealed" on sentinel element
  • Active search: hx-get with hx-trigger="input changed delay:300ms" and hx-indicator
  • Bulk operations: use hx-include to gather checkbox values, hx-vals for extra data

Forms

  • hx-post on forms, not buttons. Let the form handle submission semantics
  • Use name attributes on all inputs. Server reads standard form data, not JSON
  • Disable buttons during submission with htmx:beforeRequest/afterRequest events
  • Return the full form with errors on validation failure, not just error messages

Organization

  • Keep htmx attributes in HTML, not added via JavaScript
  • Server-side partials/fragments for reusable components
  • Use hx-boost="true" on body or nav for automatic AJAX navigation

Read the full file on GitHub · 47 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 47 lines · 529 tokens per session scan A eee419fb37ef

Subscribe to this mod's changes

htmx is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 529 tokens to every session, about $0.0026 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.