Follow the user preference
Advertise support for both schemes on the root element.
:root { color-scheme: light dark; }
The color-scheme property tells the browser which light and dark schemes an element can render correctly. The browser can then match built-in controls, scrollbars, and default canvas colors to the chosen scheme.
Declare your component colors too. This property mainly coordinates browser-provided UI.
color-scheme: normal | light | dark | light dark | only light;Advertise support for both schemes on the root element.
:root { color-scheme: light dark; }Give one subtree dark browser controls.
.dark-panel {
color-scheme: dark;
background: #111827;
color: #f8fafc;
}only light keeps a light control inside otherwise dark content.
.payment-form { color-scheme: only light; }color-scheme controls browser-rendered UI.
Supported in current Chrome, Edge, Firefox, Safari, and Opera.
Bottom line: Safe for current browsers. Always test your own foreground and background colors in every declared scheme.
Flow content into multiple columns.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
5 people found this page helpful