Dark Mode End to End: OS Preference, Toggle, and No Flash of White
Respect the system setting, let users override it, remember the choice, and never flash the wrong theme on load - the complete wiring across CSS, JS and PHP.
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.
Respect the system setting, let users override it, remember the choice, and never flash the wrong theme on load - the complete wiring across CSS, JS and PHP.
The gray-box loading experience becomes a soft preview of the real image - generated at upload with GD, inlined as a data URI, crossfaded away on load.
Search-as-you-type touches four failure modes at once - request spam, stale responses, LIKE wildcards and unbounded scans. The complete pattern, both sides of the wire.
Every chat box and comment field ships JS that measures scrollHeight to grow the textarea. One CSS property now does it natively - with a progressive-enhancement story for the rest.
Half your dark-mode CSS is pairs of rules flipping the same property. light-dark() collapses each pair into one line - and color-scheme unlocks free dark UI from the browser itself.
Order confirmations, tickets, recipes, documentation - they get printed and PDF-saved daily. Twenty lines of @media print separates professional from embarrassing.
The material-style label that sits in the field and floats up when you type is a pure CSS pattern - one pseudo-class, one sibling selector, one transition.
Scroll to the bottom of a dropdown or chat panel and the page behind starts moving - scroll chaining. One property contains it, no JavaScript scroll-locking required.
Content jumps sideways when navigating between short and long pages because the scrollbar appears and steals width. One property reserves the space permanently.
The soft fade at the bottom of a collapsed article, scroll hints on overflowing tabs, icon recoloring from a single SVG - all one property that composites with gradients.
margin-left breaks the moment your site meets Arabic or Hebrew. Logical properties describe direction-relative intent - and they are more ergonomic even if you never localize.
document.startViewTransition snapshots your page, lets you mutate the DOM, and animates between the two states - list reorders and theme switches suddenly look expensive.