htmx: High Power Tools for HTML for Modern Web Interfaces

htmx: High Power Tools for HTML for Modern Web Interfaces

Summary

htmx is a lightweight, dependency-free JavaScript library that extends HTML with powerful capabilities for building modern user interfaces. It allows developers to access AJAX, CSS Transitions, WebSockets, and Server Sent Events directly in HTML using attributes, simplifying web development by completing HTML as a hypertext.

Repository Info

Updated on December 1, 2025
View on GitHub

Tags

Click on any tag to explore related repositories

Introduction

htmx is a modern, dependency-free JavaScript library that empowers developers to build dynamic user interfaces directly within HTML. It extends HTML's capabilities, allowing you to access AJAX, CSS Transitions, WebSockets, and Server Sent Events using simple attributes. This approach simplifies web development by enabling rich interactivity without extensive JavaScript frameworks, promoting the simplicity and power of hypertext. htmx is notably small, around 14KB minified and gzipped, and is highly extendable.

Installation

You can quickly integrate htmx into your project using a CDN or by installing it as a Node package.

To include htmx via CDN, add the following script tag to your HTML:

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

To install using npm:

npm install htmx.org --save

Note: Ensure you install htmx.org as there is an older, unrelated package named htmx.

Examples

htmx makes it straightforward to add dynamic behavior. Here's a quick example demonstrating how to make a button trigger an AJAX request and update its content:

  <button hx-post="/clicked" hx-swap="outerHTML">
    Click Me
  </button>

In this example, the hx-post attribute tells htmx to issue an AJAX POST request to /clicked when the button is clicked. The hx-swap="outerHTML" attribute instructs htmx to replace the entire button element with the response received from the server.

Why Use htmx?

htmx addresses fundamental limitations in traditional HTML, challenging the arbitrary constraints that restrict its capabilities. It questions why only <a> and <form> tags should make HTTP requests, why only click and submit events should trigger them, and why only GET and POST methods should be available. Furthermore, it challenges the notion that only the entire screen can be replaced. By removing these constraints, htmx completes HTML as a true hypertext, allowing for more flexible and powerful web interactions directly from your markup. It is the successor to intercooler.js, building on its principles.

Links