Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Htmx Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-htmx-knowledge-patch)
---
name: htmx-knowledge-patch
description: htmx
version: "4.0.2"
license: MIT
metadata:
author: Nevaberry
---
# htmx knowledge patch
Load this skill when upgrading htmx or working with its requests, triggers,
swaps, history, extensions, security settings, or web components.
Use the topic references for complete guidance and examples, including
release-specific changes and the dated roadmap proposals.
## Reference index
| Reference | Topics |
| --- | --- |
| [Migration and configuration](references/migration-and-configuration.md) | Extension upgrades, removed files, module builds, declarations, scrolling, inheritance, npm tags, project policy |
| [Events and JavaScript](references/events-and-javascript.md) | Trigger filters and cancellation, boosted and intersection triggers, confirmation, transitions, lifecycle events, inline handlers, shadow roots |
| [Extensions and security](references/extensions-and-security.md) | Origin allowlisting, stylesheet nonce, attribute tools, SSE and WebSocket attributes, reconnection, live bindings, downloads, extension context |
| [History and caching](references/history-and-caching.md) | Restoration requests, GET cache separation, cache bypass, planned server-backed history |
| [Requests and validation](references/requests-and-validation.md) | DELETE parameters, AJAX context, native validation, path and dynamic URLs, parameter replacement, JSON forms |
| [Swaps and responses](references/swaps-and-responses.md) | Public swap API, templates, nested out-of-band swaps, partials, status rules, scroll targets, JSON responses, mock responses, planned morphing and streaming |
## Migration and compatibility changes
### DELETE endpoint compatibility
htmx 2 sends `DELETE` parameters in the query string by default. To keep
form-encoded bodies for existing DELETE endpoints, limit URL parameters to GET:
```js
htmx.config.methodsThatUseUrlParams = ["get"];
```
### Extension upgrades and removed files
Extensions have independent versions. htmx 2 requires an updated SSE extension,
even though most 1.x extensions still work. Enable `htmx-1-compat` during an
htmx 2 upgrade to restore most htmx 1 behavioral defaults.
4.0.1 removes the stale `hx-compat` and `hx-optimistic` files from `dist/ext`.
### SSE, WebSocket, and live API migration
For 4.0.2, migrate `sse-*` and `ws-*` attributes to `hx-sse:*` and `hx-ws:*`.
For example, use `hx-sse:swap="message"` and `hx-ws:send`.
Starting in 4.0.2, load the `hx-live` extension before calling `htmx.live`;
the extension registers the API when it loads.
### Inheritance settings
Set `disableInheritance` to `true` to make inheritance opt-in, then use
`hx-inherit` on the ancestor to name the attributes its descendants should inherit:
```html
<meta name="htmx-config" content='{"disableInheritance":true}'>
<div hx-target="#results" hx-inherit="hx-target">
<button hx-get="/results">Refresh results</button>
<div id="results"></div>
</div>
```
Starting in 4.0.1, `implicitInheritance` excludes HTTP verb attributes,
`hx-action`, and `hx-trigger`. Declare these on the elements that use them.
The November 2025 roadmap proposes opt-in inheritance per attribute with
`:inherited` on the ancestor and plans an option to restore implicit inheritance.
### Lifecycle names in the November 2025 roadmap
The roadmap switches AJAX from `XMLHttpRequest` to `fetch()` and adopts
`htmx:<phase>:<system>[:<sub-action>]` lifecycle names. Its pre-request listener
migration is from `htmx:beforeRequest` to `htmx:before:request`.
## Requests and validation
### AJAX context and browser feedback
Every property of `HtmxAjaxHelperContext` is optional, so `htmx.ajax()` can
supply only the options it needs:
```js
htmx.ajax("GET", "/status", { target: "#status" });
```
htmx blocks invalid form submissions by default. Set
`htmx.config.reportValidityOfForms = true` to also show the browser's validation
message and focus the first invalid input.
### Response status rules
`htmx.config.responseHandling` uses the first matching `code` regex. Add a rule
before the default `[45]..` rule to render a validation fragment with status 422
and treat it as a normal response:
```js
htmx.config.responseHandling.unshift({ code: "^422$", swap: true, error: false });
```
### Asynchronous confirmation
`htmx:confirm` fires for every request trigger, including elements without
`hx-confirm`. Cancel it with `preventDefault()` and call
`event.detail.issueRequest()` after the user approves. The events reference
contains the dialog example.
## Swaps and response fragments
### Public HTML swapping
`htmx.swap()` replaces the internal `selectAndSwap()` and inserts HTML using
an htmx swap style:
```js
htmx.swap(document.getElementById("status"), "<strong>Saved</strong>", {
swapStyle: "innerHTML"
});
```
### Table rows and nested out-of-band swaps
Wrap a standalone table row in a response `<template>` so the HTML parser
preserves the row for an out-of-band replacement:
```html
<template>
<tr id="result-row" hx-swap-oob="true"><td>Saved</td></tr>
</template>
```
Set `htmx.config.allowNestedOobSwaps = false` to suppress out-of-band swaps
nested within the main response fragment. This lets a fragment containing
out-of-band markers be reused as ordinary page content.
htmx also accepts template contents consisting entirely of plain text.
### Released partial response elements
htmx 2.0.11 backports the released `<hx-partial>` tag from htmx 4. Set
`hx-target` on each partial in the response to direct it to a separate element:
```html
<hx-partial hx-target="#status">Saved</hx-partial>
```
In 4.0.1, responses containing only partials leave the main body intact,
and partials honor `ignoreTitle`.
The November 2025 roadmap's proposed `<htmx-partial>` element, morphing swap
styles, and streaming responses are documented in the swaps reference.
## History and caching
On a history cache miss, restoration carries `HX-History-Restore-Request: true`
and expects a full page. If the server uses `HX-Request` to choose between a
full page and a fragment, set `htmx.config.historyRestoreAsHxRequest = false`
to omit `HX-Request` from restoration requests.
When you cannot set `Vary: HX-Request`, set
`htmx.config.getCacheBusterParam = true` to separate htmx GET cache entries from
browser navigations to the same URL. htmx appends
`org.htmx.cache-buster=<target-id>` to the GET URL.
The `no-cache` extension bypasses client caches and sends an `hx-no-cache`
request header that the server can use to bypass its cache.
## Triggers and web components
### Delegation and pending triggers
`from:` resolves its selector once, so listen on a stable ancestor when swaps
can replace descendants. In bracket filters, bare names resolve against the
triggering event first, then global scope. `this` is the element with `hx-trigger`.
```html
<div hx-get="/summary" hx-trigger="click[target.matches('button.refresh')] from:body"></div>
```
In 4.0.1, any trigger on the same element could cancel a pending `delay` or
`throttle`. Starting in 4.0.2, only triggers in the same `hx-trigger` value can
cancel it; an `hx-on` handler leaves the pending trigger in place.
Starting in 4.0.1, `hx-trigger` on a boosted link or form customizes when it
sends a request. In 4.0.1, `intersect` gained `from:` to observe a separate element.
### Shadow roots
htmx's document scan skips shadow roots. After rendering a component's markup,
pass the root returned by `attachShadow()` to `htmx.process(root)`, including
when the root is closed.
`hx-target` resolves selectors within the current shadow root by default.
Use `hx-target="host"` for the element hosting that root, or prefix a selector
with `global` to resolve it against the main document.
## Security settings
### Additional request origins
`selfRequestsOnly` defaults to `true`. To allow specific extra origins,
register `htmx:validateUrl` before disabling that setting and cancel requests
whose `event.detail.url` is outside the allowlist:
```js
document.body.addEventListener("htmx:validateUrl", (event) => {
const { sameHost, url } = event.detail;
if (!sameHost && url.origin !== "https://api.example.com") event.preventDefault();
});
htmx.config.selfRequestsOnly = false;
```
### Request-indicator stylesheet nonce
Set `inlineStyleNonce` before htmx initializes so its request-indicator
stylesheet carries the nonce from the page's Content Security Policy:
```html
<meta name="htmx-config" content='{"inlineStyleNonce":"SERVER_NONCE"}'>
```