This is a personal playground and reference set to explore the features of HTMX using PHP as the backend.
Inspired by curiosity and a desire to "swim into" HTMX, this mini-project will serve as a growing collection of examples demonstrating specific HTMX attributes and behaviors.
Because most (or maybe some) of us grew up building traditional MPA flows. Shifting to HTMX's minimal requests and DOM swapping feels like 'unlearning gravity'.
I am looking for some examples using PHP but i find little and htmx feels a little different, so i hope this would help sort out some of HTMX features using PHP, this would also help future me and the other 'similar' me people, HAHA.
Each example:
- Is linked from the main
index.php - Demonstrates a specific HTMX feature.
- Uses only PHP + HTMX, and some javascript.
- Is made as simple as possible. Just to grasp the idea.
| Feature | Page | Description |
|---|---|---|
| hx-swap-oob | swap-oob.php |
Update a part of the DOM that isn’t the target |
| hx-indicator | indicator.php |
Show a loading animation while request is pending |
| hx-get vs hx-post | get-vs-post.php |
See how different HTTP methods behave |
| Fragment loading | fragment-load.php |
Load partial responses dynamically |
| hx-trigger (keyup) | trigger-custom.php |
Auto-search while typing |
| hx-include | include-extra.php |
Submit multiple fields |
| hx-confirm | confirm-action.php |
Prompt before action |
| Polling | polling.php |
Auto update every few seconds |
| hx-push-url | push-url.php |
Dynamic URL updates |
| hx-swap modes | swap-modes.php |
Visual DOM insertion styles |
| htmx:afterSwap | afterswap.php |
fires a little earlier vs. afterSettle, good for logic, not always ideal for visual transitions. |
| htmx:afterSettle | aftersettle.php |
Add animation or logic after DOM update |
| Tabs via HTMX | tabs.php |
Tabs via HTMX |
| Chained dropdowns | chained-select.phpp |
n.a. |
| Paginated fruits list | pagination.php |
Load 5 items at a time |
| Loading spinner | spinner-delay.php |
Loading spinner (delayed) |
| HTMX Slideshow | slideshow.php |
Load slides from folder for presentations |
| Comment Box | comment-box.php |
Form Submission + Reset |
| Dynamic Alert | oob-alert.php |
hx-swap-oob in action i.e. show global messages or notifications outside the main target. |
these are just some of the examples, I will add some more and update this README.md
- PHP 7.4+ or PHP 8+
- A local server (e.g. Apache, PHP built-in server)
- Internet access to load HTMX via CDN
- If you have intermittent/slow internet, you may use the files inside the htmx_cdn folder in order for you to test the htmx samples locally.
if you placed it inside a folder, like this "c:/wamp64/www/myhtmxtrainer" Run Locally on browser, type "localhost/myhtmxtrainer/"