ConfigsApr 3, 2026·2 min read

htmx — Dynamic HTML Without JavaScript

Add AJAX, WebSockets, and CSS transitions to HTML with attributes. No JS framework needed. 47K+ GitHub stars.

TL;DR
htmx adds AJAX and dynamic behavior to HTML with attributes, no JS framework.
§01

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.

§02

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.

§03

How to use

  1. Include htmx:
<script src="https://unpkg.com/htmx.org@2"></script>
  1. 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>
  1. The server returns HTML fragments, not JSON.
§04

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> -->
§05

Related on TokRepo

§06

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

Do I need to know JavaScript to use htmx?+

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.

How does htmx compare to React?+

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.

Can htmx handle streaming responses?+

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.

Does htmx work with any backend language?+

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.

Is htmx production-ready?+

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)
🙏

Source & Thanks

Created by Big Sky Software. Licensed under BSD-2-Clause.

htmx — ⭐ 47,700+

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets