htmx — Dynamic HTML Without JavaScript
Add AJAX, WebSockets, and CSS transitions to HTML with attributes. No JS framework needed. 47K+ GitHub stars.
What it is
htmx is a JavaScript library that extends HTML with attributes for making AJAX requests, handling WebSocket connections, and triggering CSS transitions. Instead of writing JavaScript or using a frontend framework, you add attributes like hx-get, hx-post, and hx-swap to your HTML elements. The server returns HTML fragments, and htmx swaps them into the page.
It targets backend developers who want to build dynamic web interfaces without learning React, Vue, or Angular, and teams that prefer server-rendered HTML over single-page application architectures.
How it saves time or tokens
htmx eliminates the need for a separate frontend build system, JavaScript framework, and API serialization layer. Your server renders HTML directly, and htmx handles the dynamic parts. For AI applications, this means you can build interactive UIs (streaming responses, live updates, form submissions) by returning HTML from your Python/Go/Ruby backend without a JSON API or React frontend.
How to use
- Include htmx:
<script src="https://unpkg.com/htmx.org@2"></script>
- Add dynamic behavior with attributes:
<!-- Click button, GET /api/result, swap inner HTML -->
<button hx-get="/api/result" hx-target="#output" hx-swap="innerHTML">
Get AI Result
</button>
<div id="output">Results appear here</div>
<!-- Form that POSTs without page reload -->
<form hx-post="/api/generate" hx-target="#response">
<input name="prompt" placeholder="Enter prompt...">
<button type="submit">Generate</button>
</form>
<div id="response"></div>
- The server returns HTML fragments, not JSON.
Example
<!-- AI chat interface with htmx -->
<div id="chat-container">
<div id="messages"></div>
<form hx-post="/api/chat"
hx-target="#messages"
hx-swap="beforeend"
hx-on::after-request="this.reset()">
<input name="message" placeholder="Ask the AI..." autocomplete="off">
<button type="submit">Send</button>
</form>
</div>
<!-- Server endpoint returns HTML like: -->
<!-- <div class='message user'>Your question</div> -->
<!-- <div class='message ai'>AI response here...</div> -->
Related on TokRepo
- AI tools for coding -- Developer tools and frameworks
- Featured workflows -- Curated developer resources
Common pitfalls
- htmx requires your server to return HTML fragments, not JSON. If your backend is built as a JSON API, you need to add HTML-rendering endpoints or use a template engine.
- Complex state management (multi-step forms, dependent dropdowns, real-time validation) can become awkward with htmx attributes alone. For highly interactive UIs, a framework may be more appropriate.
- SEO works well since htmx enhances server-rendered HTML. However, search engine crawlers may not follow htmx-triggered content loads, so ensure important content is in the initial HTML.
Frequently Asked Questions
No. htmx is designed for developers who prefer writing HTML and server-side code. You add attributes like hx-get, hx-post, and hx-swap to HTML elements, and htmx handles the AJAX requests and DOM updates. Some advanced features (custom events, extensions) may benefit from basic JavaScript knowledge.
React is a full frontend framework with client-side rendering, virtual DOM, and a JavaScript-heavy development model. htmx enhances server-rendered HTML with dynamic behavior using attributes. htmx is simpler and requires less tooling but is less suited for highly interactive single-page applications.
Yes. htmx supports Server-Sent Events (SSE) through the hx-ext='sse' extension. Your server can stream HTML chunks, and htmx appends them to the page in real time. This works well for streaming AI responses character by character.
Yes. htmx is backend-agnostic. Any server that returns HTML over HTTP works -- Python (Django, Flask, FastAPI), Go, Ruby (Rails), PHP, Java, Node.js, and more. The server just needs to return HTML fragments instead of JSON.
Yes. htmx is used in production by many companies. It weighs about 14KB minified and gzipped, has no dependencies, and has been stable since version 1.x. The library is well-documented and has an active community.
Citations (3)
- htmx GitHub Repository— htmx extends HTML with AJAX, WebSocket, and transition attributes
- htmx Documentation— htmx enables dynamic web pages without JavaScript frameworks
- Hypermedia Systems Book— Hypermedia-driven applications return HTML instead of JSON
Related on TokRepo
Source & Thanks
Created by Big Sky Software. Licensed under BSD-2-Clause.
htmx — ⭐ 47,700+
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.