Posts

Showing posts with the label elena

How to stop theme flash in dark mode toggle

Image
Table of contents Understanding theme flash problem Why it happens in Mediumish Preventing theme flash using CSS Preventing theme flash using JavaScript Best practices for smooth theme loading FAQ Understanding theme flash problem The theme flash problem occurs when your site loads with the wrong color scheme for a split second before applying the user's saved preference. In dark mode -enabled sites like Mediumish, this is noticeable: a white background flashes before switching to dark, or vice versa. While the flash might seem minor, it can disrupt the reading experience, especially for users in dark environments. Reducing or eliminating it helps create a polished, professional feel. Why it happens in Mediumish Mediumish loads CSS and JavaScript in sequence. If your theme preference is stored in localStorage or cookies , JavaScript must read it and then apply a class or data attribute. This happens after the HTML is rendered, m...