:has() Is the Parent Selector We Waited Twenty Years For
Style a form field wrapper based on the input inside it, a card based on whether it has an image, a layout based on its content - all in pure CSS with :has().
Software Engineer
I build web applications and share what I learn along the way.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
Style a form field wrapper based on the input inside it, a card based on whether it has an image, a layout based on its content - all in pure CSS with :has().
Users almost never report the JavaScript errors they hit. A global error handler, sendBeacon and a tiny PHP endpoint give you a self-hosted crash log for free.
That html`...` syntax in lit and friends is not magic - it is a plain JavaScript feature you can use to build an XSS-safe HTML helper in fifteen lines.
Intl.NumberFormat handles currencies, compact notation, percentages and units in the user's locale - the kind of formatting everyone installs a package for.
Checking window.innerWidth on every resize event is wasteful and drifts out of sync with your CSS. matchMedia gives JavaScript the same breakpoints CSS uses, with change events.
new FormData(form) reads every field in one call, posts natively with fetch, and Object.fromEntries turns it into JSON. You may never write form.elements loops again.
Focus trapping, Escape to close, a backdrop, top-layer stacking above every z-index - the native dialog element does all of it with zero JavaScript dependencies.
Ctrl+V with an image on the clipboard fires a paste event carrying a real File object. Ten lines of code turn any form into a screenshot-friendly uploader.
Analytics batching, prefetching, cache warming - none of it should compete with user interaction. requestIdleCallback runs your low-priority work in the gaps.
When a third-party script injects, moves or mangles your markup, you cannot patch their code - but you can watch the DOM itself and react the instant it changes.
Scroll listeners fire hundreds of times per second and need throttling, math and luck. IntersectionObserver watches a sentinel element and calls you exactly when it matters.
Type document.designMode = "on" in the console and the entire page becomes editable like a document. Absurdly useful for copy reviews, screenshots and layout testing.