On this page
  1. Responsive Design & Theming
  2. Contents
  3. Design Tokens & Automatic Light/Dark Theming
  4. Fluid Spacing & Reduced Motion

Responsive Design & Theming

Prev: Modern Layout: Flexbox & Grid | Up: tutorials | Next: javascript
Rel: Media & Container Queries, Color & Value Functions, Custom Properties & Animation
Ref: MDN Web Docs — Responsive Design
Tags: #public #web #css #tutorials #responsive #theming


Contents


Design Tokens & Automatic Light/Dark Theming

Combine color-scheme, light-dark(), and CSS custom properties to support OS themes plus an explicit manual toggle (data-theme="dark"):

:root {
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #121417);
  --surface: light-dark(#f5f7fa, #1c2026);
  --text: light-dark(#1a1d21, #eef1f5);
  --accent: oklch(58% 0.18 250);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
}

Fluid Spacing & Reduced Motion

:root {
  --section-pad: clamp(1.5rem, 4vw, 4rem);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

Linked from

Related notes