</> htmx
🚧 htmx 4.0 is under construction. Read changes →

Changes in htmx 4.0

htmx 4.0 is a ground up rewrite of the implementation of htmx, using the fetch() API. This document outlines the major changes between htmx 2.x and htmx 4.x.

If you are upgrading from htmx 2.x, see the htmx 2.x → 4.x Migration Guide for step-by-step instructions, including attribute renames, removed attributes, event name mappings, and HTTP header changes.

Major Changes

fetch() API replaces XMLHttpRequest

All AJAX requests now use the native fetch() API instead of XMLHttpRequest.

Explicit Attribute Inheritance

Attribute inheritance is now explicit by default, using the :inherited modifier (e.g. hx-target:inherited="value"). This improves locality of behavior by making inheritance visible in the markup.

Event Naming Convention Changed

Events now use a colon-separated naming convention: htmx:phase:action[:sub-action].

History Storage

History no longer uses localStorage to store snapshots of previous pages.

Non-200 Swapping Defaults

In htmx 4.0, all responses will swap by default, not just 2xx responses.

GET/DELETE Form Data

Like hx-get, hx-delete does not include the enclosing form’s inputs by default. Use hx-include="closest form" if you need this behavior.

Out-of-Band Swap Order

Out-of-band (hx-swap-oob) and partial swaps now happen after the main content swap, rather than before as in htmx 2.

Default Timeout

htmx 4 sets a default request timeout of 60 seconds (htmx.config.defaultTimeout = 60000).

Extension Loading

Extensions no longer use the hx-ext attribute. They are activated by including the script file and approving them via config:

<meta name="htmx-config" content='{"extensions": "sse, ws"}'>
<script src="/path/to/htmx.js"></script>
<script src="/path/to/ext/hx-sse.js"></script>

New Features

Morphing Swap

htmx now ships with morph swap styles based on the original idiomorph algorithm.

hx-config Attribute

The new hx-config attribute allows per-element request configuration.

HTTP Status Code Conditional Swapping

The new hx-status:XXX attribute pattern allows different swap behaviors based on HTTP response status.

hx-partial Tags

The new <hx-partial> tag allows multiple targeted swaps in a single response, providing a cleaner alternative to out-of-band swaps.

hx-action and hx-method

The hx-action and hx-method attributes have been added alongside hx-get for people who want an API more consistent with the existing browser attributes

Modern Swap Terminology

New modern swap style names are supported alongside the traditional names:

Inheritance Attribute Modifiers

A new :append modifier for attributes can be used to append values to inherited values

View Transitions

View Transitions API support is available but disabled by default.

Scripting API

New async helper methods make it easier to integrate custom JavaScript with htmx.

Unified Request Context

All events now provide a consistent ctx object with request/response information.

Etag / Conditional Requests

htmx 4 has built-in support for Etag-based conditional requests.

JSX-Compatible Attribute Names

The new metaCharacter config option allows replacing : in attribute names with a custom character for frameworks that don’t support colons in attribute names.

Server-Sent Events Extension

SSE support is provided via the SSE extension, rewritten from scratch for htmx 4.

Core Extensions

htmx 4 ships with 9 core extensions:

Name Description
alpine-compat Alpine.js compatibility — initializes Alpine on fragments before swap and preserves Alpine state during morph operations
browser-indicator Shows the browser's native loading indicator (tab spinner) during htmx requests
head-support Provides support for merging head tag information (styles, etc.) in htmx requests
htmx-2-compat htmx 2.0 backwards compatibility — restores implicit inheritance, old event names, and previous error-swapping defaults
optimistic Immediately shows expected content from a template before the server responds, then replaces it with the actual response on completion
preload Triggers requests early (on mouseover or mousedown) so the response is cached by the time the user clicks, making pages appear to load nearly instantaneously
sse Adds support for Server-Sent Events streaming to htmx
upsert Adds an upsert swap strategy that updates existing elements by ID and inserts new ones, preserving elements not in the response
ws Provides bi-directional communication with Web Sockets servers directly from HTML

See the Extensions documentation for details.