Member-only story
I Stopped Using JavaScript for Menus
HTML and CSS now handles what JS used to
For years, I wrote the same 100 lines of JavaScript every time I needed a dropdown.
Read Free for non-members.
Calculate position. Track scroll. Handle resize. Fix mobile bugs. Add escape key logic. Patch the weird stuff that only breaks in production.
Not because I liked it.
Because I thought I had no choice.
Then one day, while playing with modern CSS, I realized something uncomfortable:
The browser was already doing the hard part.
The real problem with menus
Menus are simple UI elements.
They just need to:
- Open near the trigger
- Stay attached while scrolling
- Never overflow the screen
- Close correctly
Yet we’ve been solving this with JavaScript math for years.
Mostly because CSS couldn’t express intent.
Now it can.







