r/htmx • u/prafandy • 2d ago
Menus, dialogs and tabs with no JavaScript, for htmx pages
Most examples for a dropdown, a modal or tabs still need a JavaScript library. But plain HTML can do most of this on its own now, and that fits htmx pages well, since they're rendered on the server anyway.
- Menus:
popover - Modals:
<dialog>withcommandfor - Tabs: radio inputs
No script to load, nothing to set up again after an htmx swap, and it keeps working with JavaScript off.
I wrote up how each one works, with the HTML: https://alloyhtml.com/articles/dropdown-dialog-tabs-no-javascript/
Disclosure: the examples use Alloy CSS, a free stylesheet I made. The HTML works without it, so you can copy it into your own pages.
Curious what you use for this today: Alpine, hyperscript, or plain HTML?
4
u/CuriousCapsicum 2d ago
I like doing as much as possible in HTML and CSS, and then using Stimulus.js to add richness and handle any other client side state. It works really well with server rendered HTML and HTMX replacement.
Unfortunately, HTML doesn’t provide total parity even now. For example, there are accessibility issues with using radio buttons to implement tabs.
3
u/Shrink_Laureate 2d ago
Wonderful.
It's a strange irony that the rise of the super-heavy SPA has coincided with HTML quietly getting better at doing these things with little or no Javascript at all.
2
u/_HMCB_ 2d ago
So Alloy is. CSS framework? Quickly looking at the docs, I really like how you’ve broken out the CSS layers. It seems logical.
2
u/ShotgunPayDay 2d ago
The tabs part would be really cool if the css could be made generic like:
But this doesn't exist just yet sadly, because computed values can't participate in the matching process yet.
1
u/erroneousbosh 2d ago
This looks like something I'd use, thanks!
0
u/TheRealUprightMan 1d ago
Now? Most of this has been javascript free for decades. I mean, <dialog> was introduced in 2013. That was 13 years ago.
Why are people acting like basic HTML is some sort of new thing? Do we really need this every few days? Glad you finally figured out HTML. Go stand over there with the rest of them