Keyboard-accessible tabs
NavigationPreloaded panels with one tab stop and predictable arrow-key navigation.
HTML + CSS + JavaScript
role="tablist" Interaction · Complete runnable example
Let readers follow their system preference or choose a light or dark appearance.
This preview runs in an isolated document. Clipboard writes and saved preferences may be blocked, and printing requires the standalone file. A dialog affects only the example. Reset reloads the original example state.
Use this pattern when a site offers an appearance preference. The System option follows operating-system changes, while explicit Light and Dark choices remain selected until the reader changes them.
The preview, copied text, and downloaded file use this same document.
<!doctype html>
<!--
MIT License
Copyright (c) 2026 MRHTML
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; connect-src 'none'; form-action 'none'; object-src 'none'; base-uri 'none'"
/>
<title>System-aware theme switcher | MRHTML</title>
<style>
/* MRHTML standalone example. No external styles, fonts, or assets. */
:root {
color-scheme: light;
--paper: #f5f3ee;
--surface: #fff;
--ink: #1e2b42;
--muted: #59657a;
--line: #d9dee7;
--soft: #eef1fb;
--blue: #344ed5;
--blue-hover: #263caf;
--button-text: #fff;
--focus: #b65716;
--error: #ad253d;
font:
16px/1.6 system-ui,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
sans-serif;
color: var(--ink);
background: var(--paper);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100svh;
display: grid;
place-items: center;
padding: 40px 24px;
}
main {
width: min(680px, 100%);
min-width: 0;
}
h1,
h2,
h3,
p {
margin: 0;
}
h1,
h2,
h3 {
line-height: 1.15;
letter-spacing: -0.045em;
}
h1 {
font-size: clamp(1.9rem, 5vw, 2.65rem);
font-weight: 650;
max-width: 570px;
}
h2 {
font-size: 1.35rem;
font-weight: 650;
}
p {
color: var(--muted);
}
button,
input,
textarea {
font: inherit;
}
button {
cursor: pointer;
}
button:disabled {
cursor: not-allowed;
opacity: 0.65;
}
button,
a,
input,
textarea {
-webkit-tap-highlight-color: transparent;
}
:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 0.65rem;
font-weight: 650;
letter-spacing: 0.13em;
text-transform: uppercase;
margin-bottom: 22px;
}
.eyebrow::before {
content: '';
width: 8px;
height: 8px;
background: var(--blue);
border-radius: 50%;
}
.intro {
font-size: 0.94rem;
max-width: 540px;
margin-top: 17px;
}
.card {
margin-top: 28px;
padding: 28px;
background: var(--surface);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow: 0 8px 28px #14264a05;
}
.card-label {
color: var(--muted);
font-size: 0.62rem;
font-weight: 650;
letter-spacing: 0.11em;
text-transform: uppercase;
margin-bottom: 11px;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 13px;
padding: 12px 19px;
min-height: 46px;
border: 1px solid transparent;
border-radius: 8px;
background: var(--blue);
color: var(--button-text);
font-size: 0.85rem;
font-weight: 600;
line-height: 1.45;
transition:
background 0.15s,
transform 0.15s;
}
.button:hover:not(:disabled) {
background: var(--blue-hover);
transform: translateY(-1px);
}
.button.secondary {
background: var(--surface);
border-color: var(--line);
color: var(--ink);
}
.button.secondary:hover:not(:disabled) {
background: var(--soft);
}
.button svg {
display: block;
width: 18px;
height: 18px;
flex: none;
}
.hint {
font-size: 0.74rem;
line-height: 1.75;
margin-top: 20px;
max-width: 570px;
}
.status {
min-height: 1.6em;
margin-top: 17px;
font-size: 0.8rem;
color: var(--ink);
overflow-wrap: anywhere;
}
.actions {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
}
[hidden] {
display: none !important;
}
@media (max-width: 430px) {
body {
padding: 30px 18px;
}
.card {
padding: 23px 20px;
}
.eyebrow {
font-size: 0.6rem;
letter-spacing: 0.11em;
}
.intro {
font-size: 0.88rem;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation: none !important;
transition: none !important;
}
.button:hover:not(:disabled) {
transform: none;
}
}
:root[data-theme='dark'] {
color-scheme: dark;
--paper: #141d2d;
--surface: #1e2a3e;
--ink: #eef2fb;
--muted: #bdc9db;
--line: #45536b;
--soft: #293752;
--blue: #a7b6ff;
--blue-hover: #c1ccff;
--button-text: #172557;
--focus: #f2be77;
}
/* Without JavaScript, the page still follows the device's dark preference. */
@media (prefers-color-scheme: dark) {
:root:not([data-theme]) {
color-scheme: dark;
--paper: #141d2d;
--surface: #1e2a3e;
--ink: #eef2fb;
--muted: #bdc9db;
--line: #45536b;
--soft: #293752;
--blue: #a7b6ff;
--blue-hover: #c1ccff;
--button-text: #172557;
--focus: #f2be77;
}
}
.theme-controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 7px;
margin: 25px 0 0;
border: 1px solid var(--line);
background: var(--surface);
border-radius: 12px;
width: fit-content;
max-width: 100%;
}
.theme-controls legend {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
}
.theme-choice {
position: relative;
cursor: pointer;
}
.theme-choice input {
position: absolute;
margin: 0;
width: 100%;
height: 100%;
inset: 0;
opacity: 0;
cursor: pointer;
}
.theme-choice > span {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 44px;
padding: 10px 17px;
font-size: 0.8rem;
border: 1px solid transparent;
border-radius: 7px;
color: var(--muted);
}
.theme-choice input:checked + span {
color: var(--ink);
background: var(--soft);
border-color: var(--line);
}
.theme-choice input:focus-visible + span {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
.theme-choice input:disabled + span {
opacity: 0.6;
}
.theme-choice .choice-symbol {
font-size: 17px;
line-height: 1;
}
.reading-card {
margin-top: 24px;
}
.reading-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
border-bottom: 1px solid var(--line);
padding-bottom: 18px;
margin-bottom: 23px;
}
.reading-toolbar > span {
font-size: 0.67rem;
color: var(--muted);
}
.window-dots {
display: flex;
gap: 5px;
}
.window-dots span {
width: 6px;
height: 6px;
background: var(--muted);
border-radius: 50%;
}
.reading-card h2 {
font-size: 1.65rem;
max-width: 420px;
}
.reading-card > p {
font-size: 0.86rem;
max-width: 460px;
margin-top: 16px;
}
.theme-footer {
margin-top: 25px;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10px 15px;
}
.theme-badge {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--ink);
padding: 5px 10px;
border: 1px solid var(--line);
border-radius: 30px;
font-size: 0.67rem;
background: var(--soft);
}
.theme-badge::before {
content: '';
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--blue);
}
.theme-footer > span:last-child {
font-size: 0.67rem;
color: var(--muted);
}
@media (max-width: 430px) {
.theme-choice > span {
padding-inline: 12px;
font-size: 0.75rem;
}
.theme-controls {
gap: 4px;
padding: 5px;
}
.reading-card h2 {
font-size: 1.5rem;
}
}
</style>
</head>
<body>
<main>
<p class="eyebrow">MRHTML / Color preferences</p>
<h1>A little more comfortable.<br />In any light.</h1>
<p class="intro">
Follow your device's appearance, or choose the theme that feels right
for you.
</p>
<fieldset class="theme-controls" id="theme-controls" disabled>
<legend>Appearance</legend>
<label class="theme-choice"
><input type="radio" name="theme" value="system" checked /><span
><span class="choice-symbol" aria-hidden="true">◐</span>System</span
></label
><label class="theme-choice"
><input type="radio" name="theme" value="light" /><span
><span class="choice-symbol" aria-hidden="true">☀</span>Light</span
></label
><label class="theme-choice"
><input type="radio" name="theme" value="dark" /><span
><span class="choice-symbol" aria-hidden="true">☾</span>Dark</span
></label
>
</fieldset>
<section class="card reading-card" aria-labelledby="reading-heading">
<div class="reading-toolbar">
<div class="window-dots" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<span>MRHTML / Interface notes</span>
</div>
<p class="card-label">Make space for the reader</p>
<h2 id="reading-heading">
Good design leaves room<br />for a personal preference.
</h2>
<p>
A thoughtful interface works with the way people read. Clear contrast,
a familiar choice, and a setting that follows them through the day.
</p>
<div class="theme-footer">
<span class="theme-badge" id="current-theme">System theme</span
><span>Same content. A different light.</span>
</div>
</section>
<p class="status" id="theme-status" role="status"></p>
<p class="hint" id="storage-note">
Your choice can be remembered when browser storage is available.
</p>
<noscript
><p class="hint">
JavaScript is off. The page follows your device theme, but the
appearance controls are unavailable.
</p></noscript
>
</main>
<script>
// MRHTML theme preference: storage is optional, including in sandboxed previews.
const storageKey = 'mrhtml-snippet-theme';
const allowedThemes = ['system', 'light', 'dark'];
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)');
const controls = document.getElementById('theme-controls');
const status = document.getElementById('theme-status');
const storageNote = document.getElementById('storage-note');
let preference = 'system';
try {
const saved = localStorage.getItem(storageKey);
if (allowedThemes.includes(saved)) {
preference = saved;
storageNote.textContent =
'Saved preference restored from this browser.';
}
} catch {
storageNote.textContent =
'Browser storage is unavailable. Your choice still works on this page.';
}
function applyTheme() {
const resolved =
preference === 'system'
? systemTheme.matches
? 'dark'
: 'light'
: preference;
document.documentElement.dataset.theme = resolved;
document.getElementById('current-theme').textContent =
`${resolved === 'dark' ? 'Dark' : 'Light'} theme`;
document.querySelectorAll('input[name="theme"]').forEach((input) => {
input.checked = input.value === preference;
});
status.textContent =
preference === 'system'
? `Following your system: ${resolved} theme.`
: `${resolved === 'dark' ? 'Dark' : 'Light'} theme selected.`;
}
controls.addEventListener('change', (event) => {
const value = event.target.value;
if (!allowedThemes.includes(value)) return;
preference = value;
applyTheme();
try {
localStorage.setItem(storageKey, preference);
storageNote.textContent = 'Preference saved in this browser.';
} catch {
storageNote.textContent =
'Browser storage is unavailable. Your choice still works on this page.';
}
});
systemTheme.addEventListener('change', () => {
if (preference === 'system') applyTheme();
});
applyTheme();
controls.disabled = false;
</script>
</body>
</html>