Switch to:
htmx: the unexpected ally of modern backend

htmx: the unexpected ally of modern backend

For some years, a library has made its way almost silently, revolutionizing the way we understand the interaction between browser and server. Today, the web front-end is dominated by frameworks like React, Angular, Vue, Svelte, but there is a new actor and it is absolutely protagonist, especially for next-generation applications.

It is called htmx, and it was released in 2020. Today it has over 45k stars on GitHub and just a couple of years ago it was ranked second among the fastest-growing front-end frameworks. But what makes htmx so interesting, especially for those developing serverless applications?

htmx is a JavaScript library that allows leveraging modern browser functionalities directly from HTML, without writing JavaScript code. It is a sort of ‘enhancement’ of the markup language, which remains at the center of the architecture. And here comes one of its strongest aspects: adherence to the classic REST model, in which HTML itself represents the application state.

With a few lines of code, this library allows interacting with the server through dynamic HTTP requests, using simply HTML attributes. Without writing JavaScript. Without configuring a client router. Without creating a ‘state manager’. Just HTML, but enhanced.

In htmx, any DOM element can send a request, and any event can be used as a trigger. You are not limited to classic clicks or submits. It is possible to react to a mouse enter, a scroll, or set automatic polling. And you are not bound to GET or POST: you can also use PUT, PATCH, DELETE.

The underlying idea is to extend the ‘hypermedia’ behavior of HTML, recovering the concept that the Web was born with: every interaction is a state transition guided by hypertexts. You do not return JSON data to interpret; you return HTML directly to insert into the page.

This philosophy marries surprisingly well with serverless architectures because each endpoint is an autonomous function, often deployed on platforms like Vercel or AWS Lambda.

Being able to build a user interface entirely based on pieces of HTML means reducing infrastructural complexity, improving response times, and having an application that can scale linearly with traffic.

Let’s see an example: suppose we want to show a list of heroes following the click of a button. With htmx it is enough to write:


<button hx-get="/heroes" hx-target="#hero-list"> Load Heroes!</button>

<div id="hero-list"></div>

When the user clicks the button, a GET request is sent, a fetch, to the /heroes endpoint. The server responds with an HTML fragment, such as:

<ul>
  <li>Ranieri</li>
  <li>Marco</li>
  <li>Hero 1</li>
  <li>Hero 2</li>
  <li>Hero n</li>
</ul>

htmx takes care of inserting it automatically inside the div with ID hero-list, replacing the previous content. The effect is immediate, reactive, and extremely simple to implement. There is no need to build the markup on the client side: the server does it, which remains at the center of the application.

Those coming from React or Vue might ask: and the state? And animations? And routing? All things possible, but to be approached from a different perspective. For example, htmx natively supports CSS transitions, using the hx-swap attribute and a small delay called ‘settle’. If a replaced element keeps the same ID and changes class, you can get a smooth transition without a line of JS.

A more dynamic example? Consider an automatic polling that updates every two seconds a section with the latest notifications:


<div hx-get="/notifications" hx-trigger="every 2s" hx-target="#alerts"></div>

<div id="alerts"></div>

In a serverless context, this is pure gold.

On the server side, you can return an updated HTML fragment every time there are new notifications, without maintaining WebSocket connections and without persistent infrastructures.

Moreover, htmx supports features like browser history management (hx-push-url), integration with custom events (hx-on:), loading indicators (htmx-indicator), request synchronization (hx-sync), and targeted element selection (hx-select). All using only HTML attributes, with a minimal learning curve.

Another advantage, often underestimated, is accessibility. Applications built with htmx are, by default, more accessible. Links remain links and forms remain forms. With the hx-boost attribute, you can transform all links and forms into AJAX requests, but keeping the traditional behavior as fallback.

Obviously, it is not the right tool for every project. If you need a hyper-interactive interface, with intensive client-side state management, complex components, and real-time updates on a large scale, you are probably better off looking elsewhere. But if the heart of the application is server-centric, and what you need is a dynamic but linear frontend, htmx can drastically reduce complexity.

It is worth clarifying, though, that htmx is not an SSR framework.

SSR (Server-Side Rendering) indicates a mechanism in which the entire page (or part of it) is generated by the server and then sent to the browser, typically in response to an initial request or navigation. htmx does not generate HTML itself, nor does it handle server-side rendering. It is rather an HTML orchestration mechanism on the client side: it allows the client to send HTTP requests via HTML attributes, and to insert HTML fragments returned by the server directly into the DOM. htmx relies on a back-end that generates HTML, so it uses SSR responses (HTML fragments generated by the server) instead of REST/JSON APIs. The typical architecture with htmx is server-driven: the client (htmx) asks, the server responds with ready-to-inject markup. This is very similar to SSR, but happens incrementally and dynamically, without reloading the entire page. htmx is not an SSR rendering engine like Next.js can be, but it is complementary to an SSR back-end.

In short, htmx offers a rare possibility in the current landscape: building modern web apps without giving up the original simplicity of the Web.

And for those developing in serverless environments, it is a concrete opportunity to do much more, but with less.

Ranieri Vannozzi

The author

Ranieri Vannozzi

Freelance software developer and consultant

I have been writing code since 2008, working on enterprise development, cloud-native architectures and technical leadership. On HeroHubs I write about what I run into every day on real projects, from code to architecture and artificial intelligence.

Article written with AI assistance and reviewed by the author.

Related Posts

Performant npm: the package manager that rethinks node_modules

Development

September 2026

Performant npm: the package manager that rethinks node_modules

Performant npm is not just a faster npm. The global store with hard links and the strict node_modules structure change the way a JavaScript project declares and uses its dependencies.

Conventional Commits: the commit message as a technical document

Development

June 2026

Conventional Commits: the commit message as a technical document

Writing commit messages freely is a convention that forms through inertia. Conventional Commits replaces it with a structure that generates value automatically.

Brute force protection: authentication that holds

Development

June 2026

Brute force protection: authentication that holds

A brute force attack is not sophisticated, but it is persistent. Building a solid defence is an architectural question first, a configuration question second.

Why is ignoring package-lock architectural suicide?

Development

May 2026

Why is ignoring package-lock architectural suicide?

Many developers treat the lock file as background noise in commits. In reality, it is the only thing standing between your code and a sudden crash in production.

Biome: the modern toolchain that simplifies web development

Development

October 2025

Biome: the modern toolchain that simplifies web development

Discover Biome: the unified toolchain for linting, formatting, and code analysis in JavaScript/TypeScript. Benefits, integration, and productivity for modern developers.

Test driven development: a silent ally for software heroes

Development

October 2025

Test driven development: a silent ally for software heroes

Learn about Test Driven Development (TDD): benefits, Red-Green-Refactor cycle, practical examples, and how TDD and BDD improve software quality and maintainability.

Astro: islands architecture and hybrid rendering for performant content

Development

October 2025

Astro: islands architecture and hybrid rendering for performant content

A guide to Astro: the modern framework for static and hybrid sites, islands architecture, server-first rendering, SEO, performance, and integration with React, Vue, and Svelte.

Feature flags: the key to safe, controlled, and continuous releases

Development

October 2025

Feature flags: the key to safe, controlled, and continuous releases

Learn how feature flags revolutionize software releases: gradual rollout, instant rollback, A/B testing, and best practices for DevOps and CI/CD.

Pull and merge requests: same goals but different approaches

Development

September 2025

Pull and merge requests: same goals but different approaches

Pull requests vs merge requests: differences, advantages, and best practices for code review on GitHub and GitLab, with a focus on DevOps and team collaboration.