On this page
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
- tuts/css/at_rules
- tuts/css/at_rules/media_and_container_queries
- tuts/css/functions
- tuts/css/functions/color_and_value_functions
- tuts/css/functions/math_and_sizing_functions
- tuts/css/properties/typography_and_color
- tuts/css/tutorials
- tuts/css/tutorials/modern_layout_flexbox_and_grid
- tuts/css/tutorials/responsive_design_and_theming
Related notes
- tuts/css/at_rules/media_and_container_queries Linked here; links to this page; shared tags: #css, #responsive, #web
- tuts/css/tutorials Linked here; links to this page; shared tags: #css, #tutorials, #web
- tuts/css/tutorials/modern_layout_flexbox_and_grid Linked here; links to this page; shared tags: #css, #tutorials, #web
- tuts/css/functions/color_and_value_functions Linked here; links to this page; shared tags: #css, #web
- tuts/css/at_rules links to this page; shared tags: #css, #web
- tuts/css/functions links to this page; shared tags: #css, #web
- tuts/css/functions/math_and_sizing_functions links to this page; shared tags: #css, #web
- tuts/css/properties/custom_properties_and_animation Linked here; shared tags: #css, #web
- tuts/css/properties/typography_and_color links to this page; shared tags: #css, #web
- tuts/javascript Linked here; shared tags: #web