Skip to content

small-tech/htmx

 
 

Repository files navigation

</> htmx

high power tools for HTML

Discord Netlify Bundlephobia Bundlephobia

introduction

htmx allows you to access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext

htmx is small (~14k min.gz'd), dependency-free, extendable & IE11 compatible

motivation

  • Why should only <a> and <form> be able to make HTTP requests?
  • Why should only click & submit events trigger them?
  • Why should only GET & POST be available?
  • Why should you only be able to replace the entire screen?

By removing these arbitrary constraints htmx completes HTML as a hypertext

quick start

  <script src="https://unpkg.com/[email protected]"></script>
  <!-- have a button POST a click via AJAX -->
  <button hx-post="/clicked" hx-swap="outerHTML">
    Click Me
  </button>

The hx-post and hx-swap attributes tell htmx:

"When a user clicks on this button, issue an AJAX request to /clicked, and replace the entire button with the response"

htmx is the successor to intercooler.js

installing as a node package

To install using npm:

npm install htmx.org --save

Note there is an old broken package called htmx. This is htmx.org.

website & docs

contributing

  • All PRs should be made against the dev branch, except documentation PRs (www/ directory) which can be made against master
  • Please write code, including tests, in ES5 for IE 11 compatibility
  • Please include test cases in /test and docs in /www
  • Search the issues before proposing a feature to see if it is already under discussion
  • If you are adding a feature, consider doing it as an extension instead to keep the core htmx code tidy
  • Want to contribute but don't know where to start? Look for issues with the "help wanted" tag
  • Refactors that do not make functional changes will be automatically closed, unless explicitly solicited (documentation typo fixes are fine)
  • No time? Then become a sponsor

hacking guide

To develop htmx locally, you will need to install the development dependencies.

Requires Node 15.

Run:

npm install

Then, run a web server in the root.

This is easiest with:

npx serve

You can then run the test suite by navigating to:

http://0.0.0.0:3000/test/

At this point you can modify /src/htmx.js to add features, and then add tests in the appropriate area under /test.

  • /test/index.html - the root test page from which all other tests are included
  • /test/attributes - attribute specific tests
  • /test/core - core functionality tests
  • /test/core/regressions.js - regression tests
  • /test/ext - extension tests
  • /test/manual - manual tests that cannot be automated

htmx uses the mocha testing framework, the chai assertion framework and sinon to mock out AJAX requests. They are all OK.

haiku

javascript fatigue:
longing for a hypertext
already in hand

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages

  • JavaScript 92.3%
  • HTML 6.9%
  • Go 0.4%
  • CSS 0.2%
  • Ruby 0.1%
  • TypeScript 0.1%