4 ms·
The details / summary feature can also be implemented with pure css without JavaScript. Here is an example: https://docs.go101.org/std/pkg/io.html https://docs.
by tapirl 9mo ago
The details / summary feature can also be implemented with pure css without JavaScript. Here is an example: https://docs.go101.org/std/pkg/io.html https://docs.go101.org/std/pkg/io.html, just click all "+" signs to expand contents.
We can also use pure css to implement tab panels. A demo: http://tmd.tapirgames.com/demos.html#section-demo-4 http://tmd.tapirgames.com/demos.html#section-demo-4
Modern css is powerful.
- xorcist 9mo agoWhat is a good reference to learn modern CSS? I seems most books and online resources are quickly outdated.
- tapirl 9mo agoI really don't know. I'm not a CSS expert. I've just picked up bits and pieces of CSS knowledge from Google and AI agents. These results often aren't perfect, so you'll need to make some adjustments.
- jakelazaroff 9mo agoNote that pure HTML and CSS implementations of tabs using <details> and <summary> fail to meet several important accessibility criteria [1]. While you can make something that visually appears to act as a set of tabs, building it accessibly unfortunately still requires JavaScript. [1] https://adrianroselli.com/2019/04/details-summary-are-not-insert-control-here.html#Tab https://adrianroselli.com/2019/04/details-summary-are-not-in...
- tapirl 9mo agoThe pure-css effects I mentioned both don't use <detail>/<summary>.
- jakelazaroff 9mo agoSame caveat applies to the "checkbox hack" or any other pure CSS solution. You cannot create accessible versions of most complex controls like tabs without JavaScript. (That first example could be created semantically and accessibly with <details> / <summary> though!)
- tapirl 9mo agofor "accessible", do you mean getting focused when pressing TAB key?
- jakelazaroff 9mo agoHere is a non-exhaustive list of issues you'll run into with various pure HTML and CSS implementations: - Tabs should have an ARIA "tab" role [1], but <summary> doesn't accept roles [2]. - Focusing a tab must activate the corresponding tab panel [3], which requires JavaScript. - Tabs should be navigable by arrow keys [4], which also requires JavaScript. I want to be clear that I'm not trying to tear down your work. Your project looks cool and eliminating JavaScript is a noble goal. But unfortunately, as of today, it's still required to correctly build most complex controls on the web. [1] https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/tab_role https://developer.mozilla.org/en-US/docs/Web/Accessibility/A... [2] https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/summary#technical_summary https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/... [3] https://w3c.github.io/aria/#tab https://w3c.github.io/aria/#tab [4] https://www.w3.org/WAI/ARIA/apg/patterns/tabs/ https://www.w3.org/WAI/ARIA/apg/patterns/tabs/
- Permik 9mo agoThis is false, recently the details element has gotten support for grouping them: the [name] attribute. This effectively enforces tab-like semantics where only one of the grouped details elements can be open at a time. This is a quite recent addition and the modern web is evolving too fast so I wouldn't put it past myself for missing this :) Yay for progress and for JavaScript free solutions!
- jakelazaroff 9mo agoNo, it's still true. I'm aware of that hack, but unfortunately it doesn't solve the problems with pure HTML and CSS tabs. Crucially, the `name` attribute does not semantically turn a group of <details> elements into a set of tabs. All it does is introduce the (visual) behavior where opening one <details> element closes the others. I posted a list of accessibility issues with the <details> hack in another comment: https://news.ycombinator.com/item?id=46415271 https://news.ycombinator.com/item?id=46415271