Learn htmx Project

The order board is every htmx lesson on one page: active search with delay:500ms, polling with every 30s, status buttons with hx-vals and outerHTML, hx-delete…

Here's what you'll build: Mrs. Rini's Laundry order board at http://localhost:8000/board, one page the cashier uses all through a busy morning. Incoming laundry is pinned at the bottom, status cards get moved along, customers' names get looked up, cards that were picked up get pulled off, and the "active orders" number in the corner changes with them. The cashier never replaces the whole board, only the cards that change.

This project puts every htmx lesson together into one whole page. Each earlier lesson gave you one tool. Here they're all used together.

The board page, in full

<header>
  <h1>Mrs. Rini's Laundry</h1>
  <span id="active-count">3 active orders</span>
</header>

<form action="/search" hx-get="/search" hx-target="#results"
      hx-trigger="input changed delay:500ms, submit">
  <input name="q" type="search" placeholder="Customer name">
</form>
<ul id="results"></ul>

<ul id="order-board" hx-get="/board" hx-trigger="every 30s" hx-swap="outerHTML">
  <li id="order-12">#12 Mr. Darto, 3 kg: <span id="status-12">Washing</span>
    <button hx-post="/order/12/status" hx-vals='{"status": "Ironing"}'
            hx-target="closest li" hx-swap="outerHTML">Ironing</button></li>
  <li id="order-13">#13 Ms. Wulan, 2 kg: <span id="status-13">Ironing</span>
    <button hx-post="/order/13/status" hx-vals='{"status": "Ready for pickup"}'
            hx-target="closest li" hx-swap="outerHTML">Ready for pickup</button></li>
  <li id="order-14">#14 Mr. Yoga, 5 kg: <span id="status-14">Ready for pickup</span>
    <button hx-delete="/order/14" hx-confirm="Has Mr. Yoga picked up order #14?"
            hx-target="closest li" hx-swap="outerHTML">Picked up</button></li>
</ul>

<form id="intake" action="/order" method="post"
      hx-post="/order" hx-target="#order-board" hx-swap="beforeend"
      hx-indicator="#loading" hx-disabled-elt="find button">
  <input name="name" placeholder="Name" required>
  <input name="weight" placeholder="kg" required>
  <button>Take in laundry</button> <span id="loading" class="htmx-indicator">Saving...</span>
</form>

The request and response map

Feature Request Trigger Target, swap Reply
Open the board GET /board address typed the whole page 200, full page
Search a name GET /search?q=wulan typing then a 500 ms pause, or Enter #results, innerHTML 200, <li> rows
Refresh the board GET /board every 30 seconds #order-board, outerHTML 200, <ul id="order-board">
Move a status POST /order/12/status, body status=Ironing click closest li, outerHTML 200, the new #12 row
Take in laundry POST /order, body name=Mrs.%20Tini&weight=4 submit #order-board, beforeend 200 new row, or 422
Hand over laundry DELETE /order/14 click then OK closest li, outerHTML 200, only an OOB piece

Every htmx request carries the header HX-Request: true. That's why GET /board can have two shapes: the full page for the browser, and just the <ul> for polling. The server picks, and how Laravel does it is in the next lesson.

One order from start to finish

Mrs. Tini hands over 4 kg. The cashier types the name and weight, then presses Take in laundry:

Time What happens
0 ms browser validation passes (both required boxes are filled), htmx sends POST /order
0 ms "Saving..." appears, the button is disabled
600 ms 200 OK: row #15 goes at the end of the board, the header becomes "4 active orders", a new empty form replaces the old one

The server's reply:

<li id="order-15">#15 Mrs. Tini, 4 kg: <span id="status-15">Queued</span>
  <button hx-post="/order/15/status" hx-vals='{"status": "Washing"}'
          hx-target="closest li" hx-swap="outerHTML">Washing</button></li>
<span id="active-count" hx-swap-oob="true">4 active orders</span>
<!-- then the empty #intake form, with hx-swap-oob="true" -->

The new row already carries the next step's button, Washing. The browser doesn't need to know the order of statuses: the server puts in the buttons that may be pressed. This is the hypermedia architecture (Hypermedia-Driven Application): the server sends HTML that holds the data and its actions, not JSON that JavaScript in the browser has to assemble into a view. That's why htmx fits server frameworks like Laravel or Django: the server renders HTML with its templates, with no separate JSON API.

When the server refuses: 422

<meta name="htmx-config" content='{"responseHandling":[{"code":"204","swap":false},{"code":"[23]..","swap":true},{"code":"422","swap":true,"error":true},{"code":"[45]..","swap":false,"error":true}]}'>

Still works without JavaScript

Take a guess first: htmx fails to load on the cashier's phone, so the page runs without JavaScript. Which still works: taking in laundry, searching a name, or moving a status?

Feature Without JavaScript
Take in laundry works: the form has action and method, the browser sends a plain POST /order, the server answers with a redirect to /board
Search a name works with Enter: GET /search?q=wulan opens a full page with the results
Move a status, Picked up don't work: a button outside a form sends nothing
Polling, indicator, confirm don't work, but every reload still brings the latest data

So taking in laundry and searching still work, moving a status doesn't. This pattern is called progressive enhancement: start from an HTML page that works on its own, then htmx makes it smoother. To make the status buttons work too, turn each into a small form: <form action="/order/12/status" method="post"> holding <input type="hidden" name="status" value="Ironing"> and the button, with the same hx-post on that form.

Checklist before you're done

  1. Every form and button has a clear target, and a list that grows uses beforeend.
  2. Replies hold only the pieces needed. Pieces outside the target carry hx-swap-oob="true", with exactly the same id.
  3. Actions that delete have an hx-confirm with a sentence.
  4. Requests that feel slow have an indicator, and their button is disabled while waiting.
  5. Forms have a real action and method.
  6. 422 is allowed to swap, and the success reply clears the error message.
  7. Search uses delay, and polling has a sensible pause (30 seconds = 120 requests per hour per tab).

⚠️ What most often messes up the board

TL;DR: The order board is every htmx lesson on one page: active search with delay:500ms, polling with every 30s, status buttons with hx-vals and outerHTML, hx-delete with hx-confirm, an hx-post form with beforeend, an indicator and hx-disabled-elt, and a counter through hx-swap-oob="true". Each feature has one row in the request map: method, address, target, swap and reply status. The server answers with HTML pieces that carry the next action: that's the hypermedia architecture, and why htmx fits Laravel or Django, which render HTML themselves. A refusal is answered with 422 plus HX-Retarget and HX-Reswap, which only swaps once 422 is allowed in htmx-config. Real forms and links keep the main features working without JavaScript.

⚡ One page, every lesson

Write:

  <li id="order-12">#12 Mr. Darto, 3 kg: <span id="status-12">Washing</span>
    <button hx-post="/order/12/status" hx-vals='{"status": "Ironing"}'
            hx-target="closest li" hx-swap="outerHTML">Ironing</button></li>

Meaning: The status button sends hx-vals, points at closest li, and swaps the whole row with outerHTML. Each feature on the board has one row in the request map: method, address, target, swap and reply status.

⚡ The server sends the next action

Write:

<li id="order-15">#15 Mrs. Tini, 4 kg: <span id="status-15">Queued</span>
  <button hx-post="/order/15/status" hx-vals='{"status": "Washing"}'
          hx-target="closest li" hx-swap="outerHTML">Washing</button></li>
<span id="active-count" hx-swap-oob="true">4 active orders</span>
Guess first: why does htmx pair so easily with Laravel or Django?

Because the server already renders HTML itself with its templates, so there's no need for a separate JSON API.

Meaning: The new row already carries the next step's button, Washing. This is the hypermedia architecture: the server sends HTML that holds the data and its actions.

⚡ Still works without JavaScript

Guess first: htmx fails to load on the cashier's phone. Which still works: taking in laundry, searching a name, or moving a status?

Taking in laundry and searching a name, because their forms have action and method. Moving a status doesn't: a button outside a form sends nothing.

Meaning: This is progressive enhancement: start from an HTML page that works on its own, then htmx makes it smoother.

What you will learn