What Is HTMX? The HTML-First Revolution Against JavaScript Fatigue

10 min read

Originally published in Turkish. Read the original →

What Is HTMX? The HTML-First Revolution Against JavaScript Fatigue - cover image
Summary

Tired of giant JavaScript frameworks like React, Vue and Angular? HTMX restores HTML's real power and lets you build modern, dynamic web applications with zero JavaScript dependencies. This 16 KB library is rewriting the rules of frontend development.

What Is HTMX? The HTML-First Revolution Against JavaScript Fatigue

The frontend development world has gone through a tremendous process of growing complexity over the past decade. React, Vue, Angular, Svelte, Solid… Every year we are expected to learn a new framework, a new build pipeline, a new state management library. In the process, HTML, the real foundation of the web, has been reduced to little more than a "skeleton". But one library is quietly rebelling against this trend: HTMX.

At only ~16 KB compressed, with no dependencies, and bringing HTML back to where it belongs (at the center), HTMX offers a serious alternative for developers suffering from "JavaScript fatigue". So what exactly is it, how does it work, and why has everyone started talking about it?

HTML's Untapped Power

To understand HTMX's philosophy, we first need to look at the basic limitations of HTML. In standard HTML, these four rules apply:

1. Only \ and \ elements can send HTTP requests 2. Only click and submit events can trigger these requests 3. Only the GET and POST HTTP methods can be used 4. Only the entire page can be replaced (full page reload)

These limitations are design decisions left over from the early days of the web. But modern applications require partial updates, real-time data flow and rich interactions. This is exactly where JavaScript frameworks come in.

HTMX, however, approaches the problem from a different angle: by removing these limitations, it turns HTML into a complete hypertext language. It delivers the same modern experience using HTML attributes instead of JavaScript.

How Does It Work? Core Concepts

HTMX's working principle is surprisingly simple. By adding special hx- attributes to any HTML element, you make that element send AJAX requests, update specific parts of the DOM and respond to various events.

AJAX Requests

HTMX lets you use all HTTP methods directly from HTML:

html
<!-- GET request -->
<button hx-get="/api/kullanicilar">Fetch Users</button>

<!-- POST request -->
<button hx-post="/api/yorum-ekle">Submit Comment</button>

<!-- PUT request -->
<button hx-put="/api/profil-guncelle">Update Profile</button>

<!-- DELETE request -->
<button hx-delete="/api/yorum/42">Delete Comment</button>

That's it. Without writing a single line of JavaScript, an HTTP request is sent to the server when a button is clicked, and the returned HTML response is automatically placed on the page.

Targeting

You specify where the returned response should be placed on the page with the hx-target attribute:

html
<input type="text" name="arama"
       hx-get="/arama"
       hx-trigger="keyup changed delay:500ms"
       hx-target="#sonuclar"
       placeholder="Search...">

<div id="sonuclar"></div>

In this example, as the user types, a request is sent to the server with a 500-millisecond delay and the results are loaded into the #sonuclar div. A live search feature, ready with zero JavaScript.

Triggers

By default, HTMX uses elements' natural events: click for buttons, submit for forms, change for inputs. But you can fully customize this with hx-trigger:

html
<!-- Triggered on mouse hover -->
<div hx-get="/detay" hx-trigger="mouseenter">
  Hover over me for details
</div>

<!-- Automatic update every 2 seconds (polling) -->
<div hx-get="/bildirimler" hx-trigger="every 2s">
  Loading notifications...
</div>

<!-- Triggered only once -->
<div hx-get="/reklam" hx-trigger="revealed once">
  Content loaded when it becomes visible
</div>

Swapping

The hx-swap attribute controls how the returned content is merged with the existing DOM:

html
<!-- Default: the inner content is replaced -->
<div hx-get="/icerik" hx-swap="innerHTML">...</div>

<!-- The element itself is replaced -->
<div hx-get="/icerik" hx-swap="outerHTML">...</div>

<!-- Appended to the end of the content -->
<div hx-get="/daha-fazla" hx-swap="beforeend">...</div>

<!-- Prepended to the start of the content -->
<div hx-get="/yeni-icerik" hx-swap="afterbegin">...</div>

Why HTMX? Real-World Advantages

1. Dramatic Code Reduction

One of HTMX's most striking claims comes from case studies showing up to 67% code reduction when real-world projects moved from React to HTMX. When the complex state management, routing and build pipeline layers of an SPA are removed, what remains is a much simpler architecture.

2. A Natural Fit with Server-Side Rendering

With HTMX, the server returns HTML directly instead of JSON. This eliminates the REST API + JavaScript rendering chain. Django, Rails, Laravel, Spring Boot, Express: whichever backend framework you use, all you need is to return HTML fragments with your template engine.

python
def arama_sonuclari(request):
    query = request.GET.get('q', '')
    sonuclar = Makale.objects.filter(baslik__icontains=query)
    return render(request, 'parcalar/sonuclar.html', {'sonuclar': sonuclar})

3. Zero Build Pipeline

HTMX is loaded from a CDN with a single script tag. Webpack, Vite, esbuild, Babel: you need none of them. The 500 MB dependency tree in your node_modules folder becomes history:

html
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.8/dist/htmx.min.js"></script>

That's all. Your project is ready to run.

4. Progressive Enhancement

HTMX is a tool you can integrate into your existing projects gradually. You don't have to rewrite the entire application from scratch. You can make a single form or a single section of your existing page dynamic with HTMX.

5. SEO and Accessibility

HTML rendered on the server side can be indexed directly by search engines. The SEO problems that come with client-side rendering are solved at the root with HTMX. In addition, using semantic HTML provides natural compatibility with screen readers and assistive technologies.

Advanced Features

WebSocket and Server-Sent Events Support

HTMX offers WebSocket and SSE support for real-time communication through its extension system. It is ideal for scenarios like live chat, notification streams and dashboard updates.

CSS Transition Animations

HTMX integrates naturally with CSS transitions during content swaps. When a request starts, the htmx-request class is added to the element, so loading indicators (spinners) and transition animations can be managed with pure CSS:

html
<button hx-get="/veri">
  Load
  <img class="htmx-indicator" src="/spinner.svg" alt="Loading...">
</button>

The htmx-indicator class is hidden by default with opacity: 0 and automatically becomes visible during the request.

Confirmation Dialogs

A built-in confirmation mechanism for sensitive operations:

html
<button hx-delete="/api/hesap"
        hx-confirm="Are you sure you want to delete your account?">
  Delete Account
</button>

Attribute Inheritance

HTMX attributes can be inherited from parent elements by child elements. This eliminates repetitive configuration:

html
<div hx-target="#sonuclar" hx-swap="innerHTML">
  <!-- Child elements automatically use this target -->
  <button hx-get="/sayfa/1">Page 1</button>
  <button hx-get="/sayfa/2">Page 2</button>
  <button hx-get="/sayfa/3">Page 3</button>
</div>

When Is HTMX the Right Choice?

HTMX is not a silver bullet for every project. But it provides serious advantages in these scenarios:

  • Content-heavy websites — Blogs, e-commerce catalogs, documentation sites
  • Admin panels and internal tools — Applications with heavy CRUD operations
  • Modernizing existing server-side applications — Adding dynamism to Django, Rails, Laravel projects
  • Prototyping and MVPs — When you want to get a working product out quickly
  • Small and medium-sized projects — Cases where a full SPA framework would be overkill

On the other hand, for applications that require complex client-side state like Google Docs, or PWAs with offline requirements, frameworks like React/Vue may still be a better fit.

Hypermedia Systems: The Book Behind the Philosophy

HTMX's creator Carson Gross explores the philosophy behind the library in depth in his book "Hypermedia Systems". Reminding us of the original vision of REST architecture, HATEOAS (Hypertext As The Engine Of Application State), the book argues that the web is actually a hypertext system and that this paradigm is still valid for modern applications.

The book can be read for free at hypermedia.systems.

Conclusion: HTML Is Enough

HTMX asks the web development world an important question: "Do we really need this much complexity?"

You don't have to deal with a 200 MB node_modules, 15-minute build times and hundreds of lines of boilerplate in every project. Most web applications can work perfectly with server-rendered HTML fragments and a few smart attributes.

By staying true to the concept of hypertext, HTMX restores the real power of the web. And this philosophy is resonating more and more among developers suffering from framework fatigue.

The haiku on HTMX's official site sums it up nicely:

> javascript fatigue: > longing for a hypertext > already in hand

Maybe the answer we were looking for was in our hands all along.

Frequently Asked Questions (FAQ)

HTMX is a library of about 16 KB compressed that sends AJAX requests via HTML attributes and inserts the returned HTML fragment into the page. The goal is to deliver the same dynamic experience without setting up a separate JavaScript framework.
You add attributes like hx-get / hx-post / hx-put or hx-delete to any HTML element. When the button is clicked an HTTP request goes to the server and the returned HTML response lands on the page without writing a single line of JavaScript.
Case studies cited in the post show up to 67 percent less code when moving from React to HTMX. Because the server returns HTML directly instead of JSON the REST API and client-side rendering chain go away.
It suits content sites / admin panels / modernizing existing server-side applications and MVPs. For heavy client state like Google Docs or offline PWA needs React or Vue remains a better fit.