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

NameDescription
head-supportProvides support for merging head tag information (styles, etc.) in htmx requests
htmx-1-compatRolls back most of the behavioral changes of htmx 2 to the htmx 1 defaults.
idiomorphProvides a morph swap strategy based on the idiomorph morphing library, which was created by the htmx team.
preloadThis 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-targetsThis extension allows you to specify different target elements to be swapped when different HTTP response codes are received.
sseProvides support for Server Sent Events directly from HTML.
wsProvides bi-directional communication with Web Sockets servers directly from HTML

Community Extensions

NameDescription
ajax-headerAdds an X-Requested-With header to all requests made by htmx
alpine-morphAlpine.js now has a lightweight morph plugin 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.
class-toolsThe 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.
client-side-templatesThis extension supports transforming a JSON/XML request response into HTML via a client-side template before it is swapped into the DOM.
debugThis extension includes log all htmx events for the element it is on, either through the console.debug function or through the console.log function with a DEBUG: prefix.
disable-elementThis 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
event-headerThis 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.
include-valsThe include-vals extension allows you to programmatically include values in a request with a include-vals attribute. The value of this attribute is one or more name/value pairs, which will be evaluated as the fields in a javascript object literal.
json-enc-customThis 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.
json-encThis extension encodes parameters in JSON format instead of url format.
loading-statesThis extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.
morphdom-swapProvides a morph swap strategy based on the morphdom morphing library.
multi-swapThis 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.
no-cacheThis 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.
path-depsThis extension supports expressing inter-element dependencies based on paths, inspired by the intercooler.js dependencies mechanism.
path-paramsThis 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.
remove-meAllows you to remove an element after a specified interval.
replace-paramsThis 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.
restoredTriggers an event whenever a back button even is detected while using hx-boost
safe-nonceThe 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
signalrProvides bidirectional real-time communication via SignalR.