Dark mode is increasingly popular in web design because it reduces eye strain and gives websites a modern look. With CSS, we can implement light and dark themes either automatically or manually.
The <prefers-color-scheme> media query allows the page to automatically switch between light and dark mode based on the user’s system settings.
This example shows how dark mode can be applied automatically according to the user’s operating system settings.
In addition to automatic switching, manual solutions are also possible, where JavaScript is used to add or remove classes on the body element.
In this example, light and dark mode can be toggled manually with CSS classes.
When implementing dark mode, ensure that content remains readable and meets accessibility standards.
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.