What is HTMX and Why You Should Care

HTMX Architecture

React is 200KB of dependencies for a contact form. HTMX is 14KB and uses HTML you already know.

HTMX lets you build dynamic web apps without writing JavaScript. Instead of onClick handlers and state management hell, you add HTML attributes like hx-get and hx-post to make AJAX requests.

Carson Gross released this in 2020 after getting fed up with the JavaScript ecosystem. Started as a side project, now companies like GitHub and 37signals are using it in production. Turns out a lot of developers were as tired of React's bullshit as Carson was.

The catch? Every click hits your server. Make sure your backend can handle it or your users will hate you.

How It Actually Works

HTMX vs React Comparison

HTMX turns any HTML element into an AJAX trigger. Click a button? It posts to your server. Server returns HTML? HTMX swaps it into the page. That's it.

Instead of sending JSON back and forth like SPAs, your server returns HTML fragments. No client-side templating. No state synchronization headaches. The server controls everything, just like 2005, but with better UX.

Except when it doesn't. I spent like 6 hours, maybe more, debugging some form that just wouldn't submit. No error messages, no console warnings, just nothing. Turns out CORS was blocking requests and HTMX was failing silently. The server logs just showed Access to XMLHttpRequest blocked by CORS policy. Spent forever thinking I'd screwed up the HTML before I checked the Network tab.

Here's The Most Basic Example

<button hx-post=\"/api/like\" hx-target=\"#like-count\" hx-swap=\"innerHTML\">
  Like this post
</button>

Click the button → POST to /api/like → server returns <span>42 likes</span> → HTMX finds the #like-count element and replaces its content. No JavaScript, no event handlers, no bullshit.

The 14KB library handles DOM updates, request management, and all the AJAX plumbing you don't want to write. Until it breaks and you're staring at empty responses wondering what went wrong.

Bundle Size Reality Check

HTMX Architecture Flow

HTMX is 14KB gzipped. React starts at 30KB for "Hello World" but grows fast once you add routing, state management, and the 47 packages you actually need in production.

Performance benchmarks show HTMX apps load faster initially, but every interaction hits the server. Fast initial load, slower clicks. Your users will notice the delay if your backend is garbage.

HTMX 2.0: What Changed

HTMX 2.0 shipped in June 2024. The big changes:

  • IE11 support dropped - Finally. Nobody cares about IE11 in 2025.
  • Extensions moved to separate repo - Less core bloat, faster releases
  • Security fix - selfRequestsOnly now defaults to true, preventing cross-domain requests
  • Better module support - Works with ESM, AMD, CJS without hassle

Most existing HTMX 1.x code works unchanged. The breaking changes are small and well documented. Check the complete changelog for full details.

But here's what they don't tell you: upgrading from 1.9 to 2.0 completely fucked our file upload feature. Took me and Jake most of a day to figure out that the new selfRequestsOnly default was blocking uploads to our CDN. Classic "backwards compatible" upgrade that breaks production at 2pm on a Friday.

Getting Started with HTMX

HTMX Getting Started

HTMX is stupidly simple to add to any page. No build process, no webpack config that takes 3 hours to understand, no npm install installing half the internet for a contact form.

Installation: Copy This Line

<script src="https://unpkg.com/htmx.org@2.0.6/dist/htmx.min.js"></script>

That's it. Put it in your HTML head and you're done. No build step.

If you're using npm because your company mandates it:

npm install htmx.org

Note: There's an old broken package called just htmx. Don't use it. You want htmx.org.

Core Concepts You Need to Know

HTMX Workflow Diagram

HTMX extends HTML with attributes that define interactive behavior:

  • hx-get, hx-post, hx-put, hx-delete: Specify HTTP methods and URLs
  • hx-trigger: Define when requests occur (click, submit, custom events)
  • hx-target: Specify which element receives the response
  • hx-swap: Control how content is inserted (innerHTML, outerHTML, append)

Here's the basic example that won't break:

<div id="user-list">
  <button hx-get="/users" hx-target="#user-list" hx-swap="innerHTML">
    Load Users
  </button>
</div>

Server-Side Reality

HTMX applications require servers that can return HTML fragments rather than JSON. This works naturally with server-side rendering frameworks:

  • Python: Django, Flask, FastAPI with template engines
  • PHP: Laravel, Symfony with Twig/Blade
  • Ruby: Rails with ERB/Haml
  • Java: Spring Boot with Thymeleaf
  • Go: Templates with html/template
  • Node.js: Express with any template engine

The server handles routing, authentication, and business logic while returning appropriate HTML responses for HTMX requests.

The Workflow Trade-offs

HTMX vs SPA Architecture

HTMX trades JavaScript complexity for server complexity:

  • No build process - Edit HTML, refresh browser. That's it.
  • No client state - Your backend holds all the state. Hope it's fast.
  • Different debugging - When HTMX breaks, you debug HTML responses in Network tab
  • Testing changes - Less frontend testing, more integration testing
  • Backend bottleneck - Every click hits your server. Optimize accordingly or prepare for angry users.

The workflow is great until it breaks and you have no idea why. I've wasted entire afternoons staring at the Network tab seeing no requests at all, thinking I'm going insane. Usually turns out I fucked up the target selector or the server was rejecting the request for some CORS bullshit I never figured out.

Frequently Asked Questions

Q

Is HTMX suitable for large-scale applications?

A

Depends. Companies are using HTMX in production, but not for their entire apps. Can it handle your React dashboard replacement? Maybe. Complex real-time collaboration features? Probably not.

HTMX is perfect for CRUD apps, admin panels, and content sites. Building the next Figma or Google Sheets? Good luck with that.

Q

How does HTMX handle SEO compared to SPAs?

A

HTMX SEO? It's fucking amazing because everything is server-rendered. Google sees actual HTML instead of empty divs waiting for JavaScript to maybe load.

SPAs are a complete shitshow for SEO. Sure, you can set up server-side rendering, but now you're rendering on both server AND client. Brilliant engineering right there.

Q

Can HTMX work with existing JavaScript code?

A

Yeah, HTMX plays nice with other JavaScript. You can drop it into existing projects without breaking everything.

But mixing HTMX with complex JS frameworks? That's where things get fucked. I've debugged codebases where half the page uses HTMX and the other half uses jQuery event handlers. When something breaks, good luck figuring out which system is causing the problem.

Q

What are HTMX's performance characteristics?

A

Fast initial load, slower interactions. Each interaction hits the server, so optimize your backend or prepare for angry users clicking buttons that feel sluggish.

The 14KB sounds great until you realize every form submission, every button click, every interaction needs a server round-trip. Hope your backend can handle it and your users have decent internet.

Q

How does error handling work in HTMX applications?

A

HTMX Error Handling

Error handling in HTMX? It's messier than they make it sound. Server returns a 500? HTMX just... does nothing. No visual feedback, no error message, just silence.

You end up writing event listeners to catch htmx:responseError and show something useful to users. And figuring out if the error is network timeout, server crash, or you fucked up the target selector? That's quality debugging time right there.

Q

Is HTMX compatible with progressive enhancement?

A

Yes. Forms and links work without JavaScript, HTMX just makes them better with AJAX when JS is enabled. Your app doesn't break when JavaScript is disabled - it just works like a regular form-based website.

This is actually one of HTMX's strongest selling points. Your app degrades gracefully when JS fails to load.

Q

How does HTMX handle authentication and security?

A

Authentication with HTMX? It just works with whatever you're already using. Cookies, sessions, JWT tokens - all the same shit works because HTMX is just making HTTP requests.

HTMX 2.0 actually broke our staging environment when they made selfRequestsOnly=true the default. Our file uploads to S3 just stopped working. No warning, no error message, just silence. Thanks for the surprise security "improvement" that killed our demo for the investors.

Q

What browser support does HTMX provide?

A

HTMX 2.x works in Chrome, Firefox, Safari, Edge. If you still need IE11 support (why??), stick with HTMX 1.x. The library uses normal web APIs so it doesn't need polyfills.

Q

How do you handle complex forms with HTMX?

A

Complex forms with HTMX? They work fine until you need file uploads, then it gets weird. And server-side validation? Good luck making error messages appear next to the right field without JavaScript.

You return HTML error fragments and pray they target the right div. I spent 3 hours figuring out why form errors were showing up in random places because I screwed up the hx-target selector.

Q

Can HTMX applications work offline?

A

No. Every click needs the server. Your app is useless without internet connection.

SPAs can cache data and work offline. HTMX apps just show broken buttons when the WiFi dies. Plan accordingly.

Q

What testing strategies work best with HTMX?

A

Testing HTMX apps is weird because most of your logic lives on the server. You test HTML responses instead of JavaScript functions.

End-to-end tests with Playwright work great because HTMX just manipulates the DOM. But trying to mock HTTP requests for unit tests? That gets messy real quick when your whole app is HTTP requests.

Q

How does HTMX compare to Web Components?

A

HTMX and Web Components solve different problems. HTMX makes regular HTML interactive. Web Components create custom elements that work everywhere.

You can use both together if you want, but honestly? Most projects pick one approach and stick with it. Mixing them gets confusing fast.

Related Tools & Recommendations

integration
Similar content

Go HTMX Alpine Tailwind: Complete Integration & Setup Guide

Go + HTMX + Alpine + Tailwind Integration Guide

Go
/integration/go-htmx-alpine-tailwind/complete-integration-guide
100%
tool
Similar content

Alpine.js Overview: A Lightweight JavaScript Framework for Modern Web

Discover Alpine.js, the lightweight JavaScript framework that simplifies frontend development. Learn why it exists, its core directives, and how it offers a ref

Alpine.js
/tool/alpine-js/overview
66%
tool
Similar content

JavaScript: The Ubiquitous Language - Overview & Ecosystem

JavaScript runs everywhere - browsers, servers, mobile apps, even your fucking toaster if you're brave enough

JavaScript
/tool/javascript/overview
62%
tool
Similar content

Django: Python's Web Framework for Perfectionists

Build robust, scalable web applications rapidly with Python's most comprehensive framework

Django
/tool/django/overview
57%
integration
Similar content

SvelteKit, TypeScript & Tailwind CSS: Full-Stack Architecture Guide

The stack that actually doesn't make you want to throw your laptop out the window

Svelte
/integration/svelte-sveltekit-tailwind-typescript/full-stack-architecture-guide
48%
tool
Similar content

Qwik Overview: Instant Interactivity with Zero JavaScript Hydration

Skip hydration hell, get instant interactivity

Qwik
/tool/qwik/overview
40%
tool
Similar content

HTMX Production Deployment - Debug Like You Mean It

Master HTMX production deployment. Learn to debug common issues, secure your applications, and optimize performance for a smooth user experience in production.

HTMX
/tool/htmx/production-deployment
40%
tool
Similar content

Next.js Overview: Features, Benefits & Next.js 15 Updates

Explore Next.js, the powerful React framework with built-in routing, SSR, and API endpoints. Understand its core benefits, when to use it, and what's new in Nex

Next.js
/tool/nextjs/overview
37%
tool
Similar content

GraphQL Overview: Why It Exists, Features & Tools Explained

Get exactly the data you need without 15 API calls and 90% useless JSON

GraphQL
/tool/graphql/overview
36%
tool
Similar content

Remix Overview: Modern React Framework for HTML Forms & Nested Routes

Finally, a React framework that remembers HTML exists

Remix
/tool/remix/overview
36%
tool
Similar content

SolidJS: React Performance & Why I Switched | Overview Guide

Explore SolidJS: achieve React-like performance without re-renders. Learn why I switched from React, what it is, and advanced features that save time in product

SolidJS
/tool/solidjs/overview
34%
tool
Similar content

Webpack: The Build Tool You'll Love to Hate & Still Use in 2025

Explore Webpack, the JavaScript build tool. Understand its powerful features, module system, and why it remains a core part of modern web development workflows.

Webpack
/tool/webpack/overview
32%
tool
Similar content

Flutter Overview: Google's Cross-Platform Development Reality

Write once, debug everywhere. Build for mobile, web, and desktop from a single Dart codebase.

Flutter
/tool/flutter/overview
31%
tool
Similar content

Vite: The Fast Build Tool - Overview, Setup & Troubleshooting

Dev server that actually starts fast, unlike Webpack

Vite
/tool/vite/overview
30%
tool
Similar content

Svelte Overview: The Compile-Time UI Framework & Svelte 5 Runes

JavaScript framework that builds your UI at compile time instead of shipping a runtime to users

Svelte
/tool/svelte/overview
30%
tool
Similar content

shadcn/ui Overview: Components, Setup & Why It Works

Explore shadcn/ui: understand why its copy-paste components are effective, learn installation & setup with the CLI, and get answers to common FAQs about this UI

shadcn/ui
/tool/shadcn-ui/overview
29%
tool
Similar content

Turbopack: Why Switch from Webpack? Migration & Future

Explore Turbopack's benefits over Webpack, understand migration, production readiness, and its future as a standalone bundler. Essential insights for developers

Turbopack
/tool/turbopack/overview
29%
tool
Similar content

Apollo GraphQL Overview: Server, Client, & Getting Started Guide

Explore Apollo GraphQL's core components: Server, Client, and its ecosystem. This overview covers getting started, navigating the learning curve, and comparing

Apollo GraphQL
/tool/apollo-graphql/overview
29%
tool
Similar content

SvelteKit: Fast Web Apps & Why It Outperforms Alternatives

I'm tired of explaining to clients why their React checkout takes 5 seconds to load

SvelteKit
/tool/sveltekit/overview
26%
tool
Similar content

React Production Debugging: Fix App Crashes & White Screens

Five ways React apps crash in production that'll make you question your life choices.

React
/tool/react/debugging-production-issues
24%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization