Features
- Any element can make HTTP requests (not just links and forms)
- Any event can trigger a request
- Server returns HTML fragments, not JSON
- CSS transition support built-in
- WebSocket and SSE support
Pros
- Dramatically simplifies architecture — no client-side state
- Works with any backend language or framework
- Tiny size (~14kb) with no dependencies
- Reduces frontend complexity by keeping logic server-side
Cons
- Requires server round-trips for every interaction
- Not suited for offline-capable or real-time collaborative apps
- Harder to build complex client-side interactions
Overview
HTMX extends HTML as a hypermedia by giving any element the ability to make HTTP requests and update the DOM with the response. Instead of exchanging JSON between a client-side JavaScript application and an API, HTMX lets your server return HTML fragments that replace parts of the page. This returns web development to the simplicity of the original hypermedia architecture while enabling modern, dynamic user experiences.
HTMX attributes like hx-get, hx-post, hx-swap, and hx-trigger can be added to any HTML element to give it dynamic behavior. The server remains the source of truth for application state, and the frontend is just HTML — no client-side routing, no state management, no build step.
When to Use
HTMX is the right choice when you want to build dynamic web applications while keeping complexity on the server, when your team’s strength is in backend development, or when you want to avoid the overhead of a JavaScript SPA framework. It pairs perfectly with server-side languages like Python, Go, Ruby, and Java.
Getting Started
<script src="https://unpkg.com/htmx.org@2"></script>
<button hx-get="/api/count" hx-target="#result" hx-swap="innerHTML">
Load Count
</button>
<div id="result"></div>