Three modes, not two
A dark mode implementation isn't really a toggle between two states. Three have to be accounted for: dark, light, and use system preference. Audio settings in many apps follow the same shape, letting a user pick a specific device or fall back to the system default.
CSS and JavaScript cover the system preference case through the prefers-color-scheme API. Trouble arrives when a stored user preference exists and no longer matches the system setting. The page can then paint the wrong theme before the correct one applies: a Flash of inAccurate coloR Theme, or FART. The name is tongue-in-cheek, but the visual result is not — it sits alongside FOUT (Flash of Unstyled Text) in the family of rendering flashes.
Why storage timing causes the flash
A saved preference has to live somewhere: a cookie, localStorage, or a database. When reading it requires JavaScript — say localStorage.getItem('color-mode-preference'); — the flash becomes likely, because that script runs after the page's first render in all but the cases where render is deliberately delayed.
Server-side rendering as a workaround
A cookie read by a server-side language before render sidesteps the problem entirely. The server can emit markup such as <html class="user-setting-dark-mode"> and the styling follows from there. The catch is that this path requires server-side access at all; Jamstack sites, for example, don't have it.
The Next.js approach and its cost
Rob Morieson's article on dark mode in Next.js takes the issue seriously rather than deferring it. It relies on localStorage, but because Next.js renders in JavaScript, the user's saved preference can be checked as the very first step, so the correct theme is produced on the initial render with no flash. The trade-off is real: server-side rendering has to be turned off for it to work.
Absent a server-side language or a forced delay before render, there doesn't appear to be a good way to avoid FART.



