Welcome to the first lesson of your course on migrating projects from React to HTMX. Given your extensive background in front-end development, our goal isn't to re-learn web fundamentals, but to master the critical mental shift from the client-centric Single-Page Application (SPA) model to the server-centric Hypermedia approach that powers HTMX.
This initial lesson lays the essential groundwork for that shift. We will dissect the fundamental architectural differences between SPAs and hypermedia-driven applications, focusing specifically on three core pillars:
- State Location: Where does the application's source of truth reside?
- Data Transfer Format: What information is exchanged between the client and server?
- Rendering Responsibility: Which side is responsible for generating the HTML that the user sees?
Understanding these distinctions is the most important step in successfully re-architecting your applications and unlocking the benefits of HTMX for the CRUD-style projects you aim to migrate.
The Client-Side Rendering (CSR) Model: The React Paradigm
As a seasoned React developer, you are intimately familiar with the SPA architecture. To establish a clear point of contrast, let's briefly formalize its key characteristics:
-
Rendering Responsibility is on the Client: The server's initial response is typically a minimal HTML document with a root element (e.g.,
<div id="root"></div>) and links to JavaScript bundles. The browser then downloads, parses, and executes this JavaScript. React takes over the root element, rendering the entire user interface client-side. This process, where React "attaches" itself to the server-rendered HTML shell, is known as hydration. -
Data Transfer Format is JSON: Once the application is running on the client, it communicates with the backend via APIs (like REST or GraphQL). The server's role is primarily that of a data provider, sending back raw, unformatted data in JSON format.
-
State Location is on the Client: The "source of truth" for the UI state lives in the browser's memory. You manage this state using tools like
useState,useReducer, the Context API, or external libraries like Redux and Zustand. The client-side state is often a synchronized copy of data from the server, but the logic for managing UI-specific state (e.g., which modal is open, form input values, loading flags) is handled entirely by the client-side framework.
This model gives you a highly interactive, app-like feel but comes with the overhead of a large initial JavaScript payload, the complexity of client-side state management, and the "interactivity gap" during hydration.
The Hypermedia Model: The HTMX Approach
HTMX revitalizes an older, server-centric web architecture, often referred to as the "hypermedia" approach. Instead of shipping an entire application runtime to the client, it extends HTML's original capabilities, allowing any element to make HTTP requests and swap the response directly into the DOM.
To get a feel for this paradigm shift, start by watching this segment from the talk "HTMX: Why You Don't Always Need a SPA Framework."
HTMX: Why You Don't Always Need a SPA Framework - Duncan Hunter - NDC Sydney 2024
The speaker, Duncan Hunter, provides a concise, high-level overview of how the HTMX flow differs from a typical SPA.
Watch the section that contrasts the two approaches, focusing on the format of the server response. Then, watch the more detailed comparison that explains the full data flow, highlighting the steps that are eliminated in the hypermedia model.
As the video illustrates, the hypermedia model fundamentally changes the division of responsibilities:
-
Rendering Responsibility is on the Server: The server doesn't just send data; it sends fully-rendered HTML fragments. Your backend, using a templating engine (which we'll set up in the next module), is responsible for generating the UI. The client's only job is to place this HTML into the correct location in the document.
-
Data Transfer Format is HTML: When an HTMX-powered element triggers a request, it expects an HTML fragment in return, not a JSON object. This is often called "HTML over the wire." The response is presentation, not just data.
-
State Location is on the Server: Because the server renders the HTML, it is the single source of truth. The state resides in your database, server-side sessions, or other backend persistence layers. There is no need for a parallel state management system on the client. The UI in the browser is simply a reflection of the application's state as it exists on the server.
This video from Kodaps Academy explains this concept of the server being responsible for display state particularly well.
HTMX, the anti JS framework (vs React)
This video discusses how HTMX is an "anti-JavaScript framework" precisely because of its philosophy on state and rendering.
Pay close attention to the segment from 02:59 to 03:37. The speaker articulates how HTMX purposefully places the responsibility of updating the display state "squarely on the backend's shoulders."
Architectural Deep-Dive
With this conceptual framework in place, let's examine the technical details and trade-offs. The resources below offer a direct, side-by-side comparison that will be highly relevant as you plan your migration.
First, take a look at this excellent technical comparison chart. It summarizes the architectural differences we've just discussed.

Now, let's dive into some reading that expands on these points. This article provides a clear, high-level architectural comparison.
htmx vs React: When Hypermedia Beats JavaScript Frameworks
This article from daily.dev directly contrasts the two architectural models, providing clear explanations and a helpful summary table.
First, read the section titled "Architecture Comparison: SPA vs Hypermedia-Driven Applications." Pay attention to the passage that explains the distinction. Then, review the summary table which neatly lays out the differences in state location, data format, and rendering.
For a more performance-oriented analysis, the following article gets into the specifics of how these architectural choices impact load times and state management complexity.
HTMX vs React—Performance and Architecture Deep-Dive - SoftwareSeni
This article provides a data-driven look at the trade-offs, which will be useful for justifying your migration decisions.
Focus on two key sections. First, read "How does initial page load performance compare between HTMX and React?" and focus on the initial paragraphs that contrast React's "empty div" with HTMX's approach. Next, in the section "How does HTMX handle state management...", read the explanation that includes a quote from HTMX's creator about the hypermedia philosophy.
By internalizing these differences, you can start to see how features in your React applications might map to this new model. A component that fetches data and renders a list becomes a server-side template. A complex client-side form state can be simplified to a server endpoint that re-renders the form with validation messages.
Key Takeaways
To conclude, let's summarize the fundamental differences in a single table:
| Dimension | React (SPA Model) | HTMX (Hypermedia Model) |
|---|---|---|
| State Location | Client-side. Managed in browser memory (hooks, stores). | Server-side. The server is the source of truth (database, sessions). |
| Data Format | JSON. The server sends raw data. | HTML. The server sends pre-rendered HTML fragments. |
| Rendering | Client-side. React builds the UI in the browser from JSON data. | Server-side. The backend builds the UI; the client just swaps it in. |
This isn't just a technical nuance; it's a profound shift in perspective. With React, you build an application that runs in the browser. With HTMX, you build a server that serves a hypermedia-driven website, where the browser returns to its original role as a powerful document viewer.
What's Next
Now that we've established the "what" and "why" of the hypermedia architecture, the next lesson will dive into the "how." We will begin Module 2: Server-Side Foundations with Express by setting up a basic Node.js and Express server. You'll learn how to configure a templating engine and serve the HTML fragments that are the lifeblood of any HTMX application, putting you on the direct path to building your first hypermedia-driven feature.
Can't find a good explanation? Sign up and we'll make it for you
Sign up