<main>
<div>
<label for="lightdark">Light/Dark Mode:</label>
<select id="lightdark">
<option value="auto">Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</div>
<div>
<label for="contrast">Contrast Mode:</label>
<select id="contrast">
<option value="auto">Auto</option>
<option value="high">High</option>
<option value="low">Low</option>
</select>
</div>
</main>
:root {
/* allow unstyled HTML to follow user preference via prefers-color-scheme */
color-scheme: light dark;
}
:root:has(#lightdark option[value="light"]:checked) {
color-scheme: light;
}
:root:has(#lightdark option[value="dark"]:checked) {
color-scheme: dark;
}
:root:has(#contrast option[value="low"]:checked) {
filter: contrast(75%);
/* only needed because of low contrast filter, which needs a declared color to work on: */
color: CanvasText;
background-color: Canvas;
}
:root:has(#contrast option[value="high"]:checked) {
& main {
background-color: Canvas;
border: 2px solid CanvasText;
}
}
@media (prefers-contrast: less) {
:root {
filter: contrast(75%);
/* only needed because of low contrast filter, which needs a declared color to work on: */
color: CanvasText;
background-color: Canvas;
}
:root:has(#contrast option[value="high"]:checked) {
filter: revert;
}
}
/* just prettifying */
body {
display: grid;
place-content: center;
min-height: 100svh;
font-family: system-ui, sans-serif;
}
main {
display: grid;
gap: 1em;
padding: 1em;
border-radius: 0.75em;
background-color: color-mix(in srgb, rebeccapurple 40%, Canvas);
}
div {
display: flex;
justify-content: space-between;
gap: 1em;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.