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>
#active-countis updated through an OOB piece in the reply (the OOB swap lesson).- The search form is an active search:
input changed delay:500mswaits for the last keystroke, andsubmitcatches Enter (the hx-trigger and active search lessons). The attributes sit on<form action="/search">, not on the<input>, so Enter still sends that form when JavaScript is off. - The board refreshes itself every 30 seconds (polling, the hx-trigger lesson), so statuses Mrs. Rini changes in the back show up too. SSE (the SSE lesson) can replace it when changes must appear right away.
- The status buttons send
hx-vals(the hx-vals lesson), point atclosest li(the hx-target lesson), and swap the whole row withouterHTML(the hx-swap lesson). - Picked up uses
hx-deleteandhx-confirm(the confirm dialog lesson). - The intake form uses
hx-postandbeforeend(the hx-post and form lessons), plus "Saving..." and a disabled button during the request (the loading indicator lesson).
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
- Empty boxes are held back by the browser through
required, with no request. - The rule "at most 30 kg" is something only the server knows. For 40 kg, the server answers 422 with the same form, holding the cashier's input and
<p class="error">The maximum weight is 30 kg.</p>, plus the headersHX-Retarget: #intakeandHX-Reswap: outerHTMLso that form is what gets swapped, not the board. - By default htmx doesn't swap 4xx replies (the hx-post lesson), and
HX-Retargetdoesn't change that. Allow 422 once in<head>with the same four rules as the form validation lesson. A 422 still swaps, but it still counts as a failure ("error": true):
<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}]}'>
- The success reply carries an empty form as an OOB piece, so the message "The maximum weight is 30 kg." goes away too. The shorter way from the form lesson,
hx-on::after-request="if (event.detail.successful) this.reset()", only empties the input boxes. The error message stays on screen.
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
- Every form and button has a clear target, and a list that grows uses
beforeend. - Replies hold only the pieces needed. Pieces outside the target carry
hx-swap-oob="true", with exactly the same id. - Actions that delete have an
hx-confirmwith a sentence. - Requests that feel slow have an indicator, and their button is disabled while waiting.
- Forms have a real
actionandmethod. - 422 is allowed to swap, and the success reply clears the error message.
- Search uses
delay, and polling has a sensible pause (30 seconds = 120 requests per hour per tab).
⚠️ What most often messes up the board
- Forgetting
beforeendon a list. The default isinnerHTML, so a new order wipes the whole board. In the Todo App exercise, the form withhx-post="/api/todos"must keephx-swap="beforeend". - A delete button with no confirm, or an empty confirm. One wrong click and someone's laundry is gone from the board. In the exercise, the
hx-deletebutton on each item needs anhx-confirmwith a sentence, such ashx-confirm="Delete this todo?". - A counter without
hx-swap-oob="true". The piece goes into the list too, and the number doesn't change. In the exercise,<span id="todo-count" hx-swap-oob="true">goes in the server's example reply. - Search with no pause. One request per letter. In the Contact Book exercise, the search box uses
hx-get="/api/contacts/search"and anhx-triggerwithdelay:300ms.
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.