Marius Gundersen bb4d877330
Added extension (#3364)
Added link to htmx-json extension

https://github.com/mariusGundersen/htmx-json
2025-07-14 18:13:39 -06:00

14 KiB

+++ title = "Extensions" +++

htmx supports extensions to augment the core hypermedia infrastructure it provides. The extension mechanism takes pressure off the core library to add new features, allowing it to focus on its main purpose of generalizing hypermedia controls.

If you are interested in creating an extension for htmx, please see Building htmx Extensions.

htmx extensions are split into two categories:

Core Extensions

Name Description
head-support Provides support for merging head tag information (styles, etc.) in htmx requests
htmx-1-compat Rolls back most of the behavioral changes of htmx 2 to the htmx 1 defaults.
idiomorph Provides a morph swap strategy based on the idiomorph morphing library, which was created by the htmx team.
preload This extension allows you to load HTML fragments into your browser's cache before they are requested by the user, so that additional pages appear to users to load nearly instantaneously.
response-targets This extension allows you to specify different target elements to be swapped when different HTTP response codes are received.
sse Provides support for Server Sent Events directly from HTML.
ws Provides bi-directional communication with Web Sockets servers directly from HTML

Community Extensions

Name Description
{% markdown() %} [ajax-header](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/ajax-header/README.md) {% end %} {% markdown() %} Adds an `X-Requested-With` header to all requests made by htmx {% end %}
{% markdown() %} [alpine-morph](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/alpine-morph/README.md) {% end %} {% markdown() %} Alpine.js now has a lightweight [morph plugin](https://alpinejs.dev/plugins/morph) and this extension allows you to use it as the swapping mechanism in htmx which is necessary to retain Alpine state when you have entire Alpine components swapped by htmx. {% end %}
{% markdown() %} [attribute-tools](https://github.com/jamcole/htmx-ext-attribute-tools/blob/main/README.md) {% end %} {% markdown() %} The `attribute-tools` extension allows you to specify attributes that will be swapped onto or off of the elements by using an `attributes` or `data-attributes` attribute. (similar to class-tools) {% end %}
{% markdown() %} [class-tools](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/class-tools/README.md) {% end %} {% markdown() %} The `class-tools` extension allows you to specify CSS classes that will be swapped onto or off of the elements by using a `classes` or `data-classes` attribute. {% end %}
{% markdown() %} [debug](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/debug/README.md) {% end %} {% markdown() %} This extension will log all htmx events for the element it is on through the `console.debug` function. Note that during dev, using `htmx.logAll()` instead can often be sufficient. {% end %}
{% markdown() %} [event-header](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/event-header/README.md) {% end %} {% markdown() %} This extension adds the `Triggering-Event` header to requests. The value of the header is a JSON serialized version of the event that triggered the request. {% end %}
{% markdown() %} [loading-states](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/loading-states/README.md) {% end %} {% markdown() %} This extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes. {% end %}
{% markdown() %} [morphdom-swap](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/morphdom-swap/README.md) {% end %} {% markdown() %} Provides a `morph` swap strategy based on the [morphdom](https://github.com/patrick-steele-idem/morphdom/) morphing library. {% end %}
{% markdown() %} [multi-swap](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/multi-swap/README.md) {% end %} {% markdown() %} This extension allows you to swap multiple elements marked from the HTML response. You can also choose for each element which swap method should be used. {% end %}
{% markdown() %} [no-cache](https://github.com/craigharman/htmx-ext-no-cache/blob/master/README.md) {% end %} {% markdown() %} This extension forces HTMX to bypass client caches and make a new request. An `hx-no-cache` header is also added to allow server-side caching to be bypassed. {% end %}
{% markdown() %} [path-deps](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/path-deps/README.md) {% end %} {% markdown() %} This extension supports expressing inter-element dependencies based on paths, inspired by the [intercooler.js dependencies mechanism](http://intercoolerjs.org/docs.html#dependencies). {% end %}
{% markdown() %} [path-params](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/path-params/README.md) {% end %} {% markdown() %} This extension uses request parameters to populate path variables. Used parameters are removed so they won't be sent in the query string or body anymore. {% end %}
{% markdown() %} [remove-me](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/remove-me/README.md) {% end %} {% markdown() %} Allows you to remove an element after a specified interval. {% end %}
{% markdown() %} [replace-params](https://github.com/fanelfaa/htmx-ext-replace-params/blob/main/README.md) {% end %} {% markdown() %} This extension uses request parameters to replace existing parameters. If given value is empty string then parameter will be deleted. This extension would be useful in situations like pagination, search that you only want to replace only few parameters instead of reset all parameters. {% end %}
{% markdown() %} [restored](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/restored/README.md) {% end %} {% markdown() %} Triggers an event whenever a back button event is detected while using `hx-boost` {% end %}
{% markdown() %} [safe-nonce](https://github.com/MichaelWest22/htmx-extensions/blob/main/src/safe-nonce/README.md) {% end %} {% markdown() %} The `safe-nonce` extension can be used to improve the security of the application/web-site and help avoid XSS issues by allowing you to return known trusted inline scripts safely {% end %}
{% markdown() %} [hx-drag](https://www.npmjs.com/package/hx-drag) {% end %} {% markdown() %} This extension allows htmx requests to be sent for drag drop {% end %}
{% markdown() %} [dynamic-url](https://github.com/FumingPower3925/htmx-dynamic-url/blob/main/README.md) {% end %} {% markdown() %} Allows dynamic URL path templating using `{varName}` placeholders, resolved via configurable custom function or `window.` fallback. It does not rely on `hx-vals`. Useful when needing to perform requests to paths that depend on application state. {% end %}
Data API
{% markdown() %} [client-side-templates](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/client-side-templates/README.md) {% end %} {% markdown() %} This extension supports transforming a JSON/XML request response into HTML via a client-side template before it is swapped into the DOM. {% end %}
{% markdown() %} [json-enc](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/json-enc/README.md) {% end %} {% markdown() %} This extension encodes parameters in JSON format instead of url format. {% end %}
{% markdown() %} [form-json](https://github.com/xehrad/form-json/blob/main/README.md) {% end %} {% markdown() %} Similar to `json-enc`, but with **type preservation**. Converts form data into structured JSON while maintaining correct types for numbers, booleans, and files (Base64-encoded). Supports nested structures using dot (`.`) or bracket (`[]`) notation. {% end %}
{% markdown() %} [json-enc-custom](https://github.com/Emtyloc/json-enc-custom/blob/main/README.md) {% end %} {% markdown() %} This extension works similarly to json-enc but allows for very complex structures, such as embedding JSON objects, lists, or handling indexes, just by using the name attribute. {% end %}
{% markdown() %} [htmx-json](https://github.com/mariusGundersen/htmx-json) {% end %} {% markdown() %} Support JSON response by transforming the html directly. This is a slightly different appreach than client-side-templates. {% end %}
Integrations
{% markdown() %} [amz-content-sha256](https://github.com/felipegenef/amz-content-sha256/blob/main/README.md) {% end %} {% markdown() %} HTMX extension for interacting with AWS services that require the content hash as part of the request for data integrity verification. {% end %}
{% markdown() %} [signalr](https://github.com/Renerick/htmx-signalr/blob/master/README.md) {% end %} {% markdown() %} Provides bidirectional real-time communication via [SignalR](https://github.com/dotnet/AspNetCore/tree/main/src/SignalR). {% end %}
Legacy
{% markdown() %} [disable-element](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/disable-element/README.md) {% end %} {% markdown() %} This extension disables an element during an htmx request, when configured on the element triggering the request. Note that this functionality is now part of the core of htmx via the `hx-disabled-elt` attribute. {% end %}
{% markdown() %} [include-vals](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/include-vals/README.md) {% end %} {% markdown() %} The `include-vals` extension allows you to programmatically include values in a request with a `include-vals` attribute. Note that this functionality is now part of the core of htmx via the `hx-vals` attribute. {% end %}