Description #
HTMX is a lightweight, declarative HTML extension library that enables dynamic AJAX, CSS transitions, WebSockets, and more—all through HTML attributes without writing JavaScript.
History #
HTMX was created by Carson Gross and released in 2020 as a spiritual successor to intercooler.js. It was developed to bring hypermedia-driven interfaces to the modern web by extending HTML’s capabilities with simple, expressive syntax.
Hello World Code #
<button hx-get="/hello" hx-target="#output">Click Me</button>
<div id="output"></div>
Server responds with:
Hello, World!
How to Run #
Option 1: Online
Try HTMX in this interactive sandbox:
https://htmx.org/examples/
Option 2: Local
Include HTMX via CDN:
<script src="https://unpkg.com/htmx.org@1.9.2"></script>
Then create a simple HTML file and use hx-get
, hx-post
, etc. with a backend route like /hello
.
Key Concepts #
- HTML-driven behavior (AJAX via
hx-get
,hx-post
) - Attribute-based API (
hx-target
,hx-swap
, etc.) - Requires no JavaScript to create dynamic UIs
- Supports SSE, WebSockets, and CSS transitions
- Works with any backend framework
- Great for progressively enhanced apps
- Easily integrates with Alpine.js, Django, Flask, etc.
- Ideal for low-JS or no-JS web stacks
- Encourages RESTful/Hypermedia architecture
- Weighs less than 15KB gzipped
Try It Online #
Fun Facts #
- HTMX enables rich interactivity using only HTML and server responses.
- It’s often used in the “Hypermedia as the Engine of Application State” (HATEOAS) model.
- HTMX is gaining popularity as an alternative to SPAs in modern, minimal web stacks.
Resources #
Official site
Docs or tutorial
GitHub or interpreter
Community or learning resources