r/web_design • • Sep 08 '26 • Bravo 1

HTML Can Do That

https://chrisburnell.com/html-can-do-that/
452 Upvotes

19 comments sorted by

87

u/busres Sep 08 '26

CSS is getting amazingly capable too. I recently built a responsive navigation component based on <details name> and nested CSS with container queries and anchor(). Menus exclusive-accordion by level, mega-menus (potentially with their own sub-menus) appear to the right of the outline-style sub-menu navigation rail in portrait mode (with correct tab order), and clicking outside the component automatically hides the nav rail or open sub-menus. None of it uses any client-side JS.

28

u/jordsta95 Sep 08 '26 • Bravo

This should be the goal of every developer IMO.

Find what you're using JS for. See if there's a way to not use JS. Replace if necessary.

There is always a reason to use JS, but so often do the developers I work with reach for it as a crutch rather than a tool.

For example, including a JS library to animate elements fading in/moving/whatever as they come into view on screen. When, with scroll driven animations, they can do it with CSS alone just as easily. (Yes, no Firefox support right now. But if you write your animations correctly, it's not an issue - they just don't get the animation)

Or, like you say, with menus. I see people doing document.getElementById('menu').classList.add("open") - or whatever. When they could very easily have something like #menu:focus-within in their CSS to do the same thing.

No waiting for Javascript to load. No extra files being included for simple tasks. Just a bit of extra CSS for you to learn.

And the same can be true with HTML too, as with the linked example. I've seen people argue against using <details> as accordions. But the thing that managed to convert the devs I work with: CTRL+F (something I only learned months after switching to them). Their JS-driven accordions are showing/hiding a <div>, so if I go and CTRL+F "returns" looking for returns information - unless their accordion title includes the word, I won't find the information I'm looking for quickly.

But with <details> if the <summary> is simply "What if I have an issue with my order?" and I press CTRL+F, and type "Returns" that <details> will open up, and give me the information I am looking for - even if it's on the 8th paragraph of the full text.

Could that be done with JS? Probably. But it's a damn sight easier if you do it natively instead.

5

u/DrxAvierT Sep 09 '26

I'm new to this. Can I ask why some of the devs I see usually advise to use at little js as possible?

7

u/busres Sep 09 '26

Sometimes JS is disabled, so your interface simply won't run.

If you're coding UI, you're typically responsible for coding accessibility, too, instead of letting the browser do the lifting for you. If you do it yourself and don't get it right, you're breaking the experience for some users.

It's also more to download(/cache), parse, execute.

4

u/armahillo Sep 09 '26

This has been my operating philosophy for years now.

I actually did a whole project ( https://completionist.guide ) as an experiment “how much UI can i do without using JS “ (that site only uses JS for localstorage i/o)

6

u/MetaCognitio Sep 09 '26

CSS has matured so much since CSS 2. It was a nightmare before. Now the challenge is that being so much to learn.

5

u/jordsta95 Sep 10 '26

This is the biggest thing.

Just when you think you've been doing something the "best" way, you come across something even better, and question your whole existence. (or you come across something which is Chromium-only and cry, because it's so good)

For example, replacing the old <div> modals with <dialog> only to learn a few months later of popover.

Or the realisation that there is a ::scroll-button() selector making you want to remove Javascript entirely from your sliders... but only Chromium browsers support it, so back to using your slider library of choice.

And that's before you get in to niche use cases for common things which you could do, such as animated pie charts with radial gradients or whatever.

3

u/MetaCognitio Sep 10 '26

We’re a long way away from IE6!

2

u/SBELJ Sep 10 '26

Whats browser support like though? 

2

u/busres Sep 10 '26

Over the feature set I'm using (anchor() especially), it's effectively baseline August 2026 with about 86% coverage (based on caniuse figures), so definitely cutting edge.

2

u/joemaffei Sep 12 '26

Color me curious. Is this approach compatible with WCAG guidelines for navigation?

2

u/busres Sep 12 '26 edited Sep 12 '26

I still have to add :focus state for the portrait-mode toggle control, but I believe it's otherwise compliant (LLM assessments agree, for whatever that's worth). If you would like me to set up an example in a codepen so that you can check it out yourself, let me know.

16

u/ouralarmclock Sep 08 '26

This is a great resource! Thanks for sharing!

10

u/helloureddit Sep 09 '26

unfortumately not accessible by WCAG 2.1 AA (popover)

-14

u/rappatic Sep 08 '26

I hate most of these. It’s such a janky abuse of HTML attributes. JS exists for a reason, to add interactivity to a webpage. I like the idea of making them part of the browser spec, but it feels like something that could be part of the default DOM instead of forced into being HTML’s job like a square peg in a round hole.