The code reduction reality of htmx
Frontend teams are replacing complex React state management with htmx, which reduces codebase sizes by 67%. The latest version 4.0.2 migrates internals to the fetch() API and introduces improved morphing swaps and new extensions for hypermedia workflows.
The case against JavaScript complexity
I see frontend teams abandoning the heavy state management required by React for the simplicity of htmx. This library reduces code base sizes by 67% when compared with React. It allows developers to access AJAX, CSS Transitions, WebSockets, and Server Sent Events directly in HTML using attributes. Why should only anchors and forms make HTTP requests? Why should only click and submit events trigger them? Why should only GET and POST methods remain available? Htmx removes these constraints to complete HTML as a hypertext. It provides a way to build modern user interfaces without the large bundles and complex state management common in traditional JavaScript frameworks. You can build interactive pages without writing extensive client-side JavaScript logic, assuming you already know the basics of HTML. This approach works well for backend developers who want to avoid the learning curve of modern-day frontend frameworks. I find that using HTML instead of JSON payloads eliminates the performance issues related to JSON serialization and deserialization. This method also ensures that data retrieved directly from the database does not require serialization to a JSON-compliant format before being sent to the frontend. The library, the successor to intercooler.js, stays small at around 14k to 16k min.gz’d. I think the decision to replace JSON with HTML is the most effective way to solve the performance and cognitive overhead associated with complex data types. Developers use attributes like hx-post and hx-swap to tell the browser to issue an AJAX request and replace a specific element with the response.
Changes in the 4.0 release
The latest stable release, version 4.0.2, arrived on November 18, 2026. This version introduces several fundamental changes to how the library handles interactions. Attribute inheritance remains explicit by default; developers must add :inherited after an attribute name to apply it to child elements. This change addresses the difficulty developers faced with implicit behavior in htmx 2. The library also migrated its internals from XMLHttpRequest to the fetch() API, a transition that simplifies the library and its extensions and provides a more modern approach to handling asynchronous requests in the browser. Event names now follow a standardized htmx:phase:action[:sub-action] format. The library also removed htmx:xhr:* events and native form validation events in favor of native browser form validation. History support no longer uses localStorage to snapshot pages, which prevented issues where third-party JavaScript libraries left behind unexpected DOM mutations. Instead, htmx re-fetches the page on back navigation and swaps it into the body or a specific element. This method ensures that third-party libraries work correctly without additional configuration. While htmx 2.x remains the latest in NPM until early 2027, the website now references version 4.0. I find the removal of the htmx:xhr:* events in favor of the fetch-based approach to be a necessary step for a modern library. Users of the 1.x code-line still have IE support, but the latest 2.x and 4.x versions have dropped it.
| Specification | Value |
|---|---|
| Library Size | 14k to 16k min.gz’d |
| Stable Version | 4.0.2 |
| Successor To | intercooler.js |
New tools for hypermedia
The new version includes morphing swaps out of the box using an improved algorithm. The <hx-partial> tag allows for more precise updates when you need to do more than replace a single element. I also find the new extensions quite capable for specific workflows. The hx-preload extension lets you preload content on mouseover to speed up requests. The hx-download extension provides native, fetch-based file downloads. You can also use hx-alpine-compat to smooth over compatibility issues between htmx and Alpine.js. For those who want a single file, the new htmx.js bundle packages htmx with the most popular extensions. The hx-live scripting solution provides DOM-based, HATEOAS-friendly reactivity. Htmx integrates with many backend frameworks, including Node.js, Django, Flask, ASP.NET, Java, Clojure, and Ruby on Rails. This portability makes it a strong candidate for teams using various server-side technologies. The library remains small, measuring approximately 14k to 16k min.gz’d. The replacement of htmx:xhr:* with the fetch API helps modern developers. The hx-history-cache extension restores history from sessionStorage to help with scripting solutions like Alpine.js. Furthermore, the library supports streaming HTML through hx-sse for text/event-stream, hx-ws for WebSockets, and hx-multipart for multipart/mixed. Developers can use the hx-target attribute with CSS selectors like closest, next, previous, or find to direct where the response loads. The hx-trigger attribute also allows for modifiers like delay to wait before an event, throttle to limit request frequency, or once to trigger a request a single time. Additionally, the hx-indicator class lets you show a loading state by changing an element’s opacity during a request. Using the hx-disabled-elt attribute can also disable elements for the duration of a request. Does the move to explicit inheritance create too much work for those on version 2?