What Is htmx? Interactive Pages Without a JavaScript Framework
htmx lets HTML elements make requests and swap in HTML from the server, using attributes like hx-get and hx-swap — so you can build interactive pages without React. How it works, examples, where it shines, where it doesn't, and how it pairs with Django, Flask, Rails and Go.
htmx is a small JavaScript library that lets you add interactivity to pages using HTML attributes instead of writing JavaScript. Any element can send a request to your server and replace part of the page with the HTML the server sends back.
It's a deliberate alternative to building everything as a single-page app with React. (SPA vs MPA)
The idea in one example
<script src="https://unpkg.com/htmx.org@2"></script>
<button hx-post="/clicked" hx-target="#result" hx-swap="innerHTML">
Click me
</button>
<div id="result"></div>
When clicked, htmx sends a POST to /clicked. Your server returns a fragment of HTML:
<p>Thanks — you clicked at 14:32.</p>
htmx puts it inside #result. No JSON, no client-side state, no build step.
The main attributes
| Attribute | Does |
|---|---|
hx-get, hx-post, hx-put, hx-delete |
Send a request when triggered |
hx-target |
Which element to update (CSS selector) |
hx-swap |
How: innerHTML, outerHTML, beforeend, afterbegin… |
hx-trigger |
What triggers it: click, change, keyup changed delay:300ms, load, every 5s |
hx-indicator |
Show a spinner while waiting |
hx-push-url |
Update the browser URL |
hx-confirm |
Ask "are you sure?" first |
A live search box
<input type="search" name="q"
hx-get="/search"
hx-trigger="keyup changed delay:300ms"
hx-target="#results">
<ul id="results"></ul>
As the user types (debounced by 300 ms), the server returns <li> items for matching results.
Why people like it
- Much less JavaScript. Your logic stays on the server, in whatever language you like.
- No build step needed — one script tag.
- Works with any back end that renders HTML: Django, Flask, FastAPI with templates, Rails, Laravel, Go. (What is Django?)
- Simple mental model — the server is the source of truth; no syncing state between front-end and back-end.
- Fast first load — pages are real HTML, good for SEO. (SSR vs CSR vs SSG)
Where it's not the right tool
- Highly interactive interfaces — design tools, complex editors, offline-first apps, rich drag-and-drop. A client-side framework fits better.
- Lots of instant UI feedback without a server round-trip. Every interaction normally goes to the server. (Pairing htmx with a tiny library like Alpine.js covers small client-side behaviours.)
- Separate mobile apps consuming the same API — they want JSON, not HTML fragments, so you'd build both.
- Team familiarity — most front-end developers and AI tools default to React.
htmx vs React
| htmx | React | |
|---|---|---|
| Where UI is built | Server (HTML) | Browser (JavaScript) |
| Data over the wire | HTML fragments | Usually JSON |
| State | Server | Client (plus server) |
| Build tooling | None needed | Usually Vite/Next.js |
| Best for | CRUD apps, dashboards, forms | Rich, app-like interfaces |
(What is React?, What is CRUD?)
Security note
Because the server returns HTML, escape user content in your templates as you would on any server-rendered page, and keep CSRF protection on for POST requests (htmx can send your CSRF token in a header). (XSS explained, CSRF explained)
EasySpawn runs server-rendered apps — Django, Flask, Rails, Go — on your own server behind HTTPS, the natural home for an htmx front end. See how it works or join the waitlist.
Related: SPA vs MPA · SSR vs CSR vs SSG · What Is Django? · React vs Vue vs Svelte
Keep reading
What Is a Headless CMS? And Does Your App Need One?
A headless CMS is a content editor with no website attached — it stores your content and hands it to your app through an API. How it differs from WordPress, the popular options, when it beats Markdown files or your own database, and when it's overkill.
SSR vs CSR vs SSG: How Web Pages Get Rendered, Explained
Server-side rendering, client-side rendering and static site generation are three answers to one question: where and when is the HTML made? How each works, the trade-offs for speed, SEO, cost and freshness, ISR in between, and which to use for which page.