htmx — Dynamic HTML Without JavaScript
Add AJAX, WebSockets, and CSS transitions to HTML with attributes. No JS framework needed. 47K+ GitHub stars.
Instalación lista para agent
Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.
npx -y tokrepo@latest install bd7355cb-83fc-4b6f-a446-2b13b92fbf26 --target codexEjecutar después de confirmar el plan con dry-run.
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.
Preguntas frecuentes
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.
Referencias (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
Relacionados en TokRepo
Fuente y agradecimientos
Created by Big Sky Software. Licensed under BSD-2-Clause.
htmx — ⭐ 47,700+
Discusión
Activos relacionados
Livewire — Build Dynamic UIs in Laravel Without Writing JavaScript
Laravel Livewire is a full-stack framework that lets you build reactive, dynamic interfaces using only PHP and Blade templates, eliminating the need for a separate JavaScript frontend.
Stimulus — Modest JavaScript Framework for Server-Rendered HTML
Stimulus is a JavaScript framework by Basecamp that connects behavior to existing server-rendered HTML via data attributes, without requiring a full client-side rendering layer or build step.
Hotwire Turbo — Fast Web Apps with HTML Over the Wire
Turbo is the core of the Hotwire approach to building modern web applications. It speeds up navigation by replacing full page loads with partial HTML updates, delivering SPA-like responsiveness without writing custom JavaScript. Turbo is used by default in Ruby on Rails and works with any backend.
Pico CSS — Minimal Classless CSS Framework for Semantic HTML
A lightweight CSS framework that styles native HTML elements without requiring utility classes, delivering elegant default styling with a single stylesheet.