CSS Variable Theme Builder - Online Light & Dark Mode
Define a set of colors for light and dark themes. Get the CSS custom properties snippet. Toggle live.
UD5 Toolkit
Online tool demonstrating prefers-color-scheme respect — Light / Dark / Auto with system preference detection
This card demonstrates how content renders under the active color scheme. Backgrounds, text, and borders adapt automatically.
| # | Item | Status |
|---|---|---|
| 1 | Alpha | Active |
| 2 | Beta | Pending |
| 3 | Gamma | Idle |
// Detect system preference
const mq = window.matchMedia('(prefers-color-scheme: dark)');
function getSystemPreference() {
return mq.matches ? 'dark' : 'light';
}
// Apply theme
function applyTheme(mode) {
const resolved = mode === 'auto'
? getSystemPreference()
: mode;
document.documentElement
.setAttribute('data-bs-theme', resolved);
localStorage.setItem('theme-preference', mode);
}
// Listen for system changes
mq.addEventListener('change', () => {
const saved = localStorage.getItem('theme-preference');
if (saved === 'auto' || !saved) {
applyTheme('auto');
}
});
// Init on page load
const saved = localStorage.getItem('theme-preference') || 'auto';
applyTheme(saved);
/* CSS Media Query */
@media (prefers-color-scheme: dark) {
:root {
--bg: #1a1a2e;
--text: #e0e0e0;
}
}
@media (prefers-color-scheme: light) {
:root {
--bg: #ffffff;
--text: #1a1a1a;
}
}
/* HTML with Bootstrap 5.3 */
<html data-bs-theme="light">
<!-- or data-bs-theme="dark" -->
</html>
/* Toggle buttons */
<button onclick="applyTheme('light')">Light</button>
<button onclick="applyTheme('dark')">Dark</button>
<button onclick="applyTheme('auto')">Auto</button>
prefers-color-scheme?It's a CSS media feature that detects whether the user's operating system is set to light or dark mode. It returns light or dark, allowing websites to automatically match the user's system preference.
Auto mode reads the system's prefers-color-scheme value via JavaScript's matchMedia API. It applies the corresponding theme and listens for real-time changes — so if you toggle your OS setting, the website updates instantly.
Use localStorage to save the user's choice (light, dark, or auto). On page load, check localStorage first — if a value exists, apply it; otherwise fall back to system preference detection.
prefers-color-scheme?All modern browsers support it: Chrome 76+, Firefox 67+, Safari 12.1+, Edge 79+, Opera 62+, and Samsung Internet. Global support is over 96% as of 2024.
Bootstrap 5.3 uses the data-bs-theme attribute. Set it to dark or light on the <html> element. Bootstrap's CSS variables automatically adjust colors, backgrounds, and component styles accordingly.
Offer three options: Light, Dark, and Auto (system). Default to Auto to respect user preference. Persist the choice in localStorage. Use CSS variables or Bootstrap's data-bs-theme for seamless transitions.
Use window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', callback). The callback fires whenever the user changes their OS-level appearance setting.
Respecting system preferences improves accessibility, reduces eye strain for users who prefer dark mode, and provides a seamless experience. It shows users that you value their personal settings and comfort.
Yes! Use @media (prefers-color-scheme: dark) { ... } in your CSS. However, this doesn't allow users to manually override the setting. For a toggle, you'll need minimal JavaScript.
data-bs-theme and CSS variables?data-bs-theme is Bootstrap's built-in mechanism that toggles all Bootstrap CSS variables at once. Custom CSS variables require manual definition for each theme, offering more control but requiring more setup.
Define a set of colors for light and dark themes. Get the CSS custom properties snippet. Toggle live.
Reset native styling on form elements with appearance: none. See before and after. Essential for custom forms.
Swap between physical and logical properties (margin‑inline vs margin‑left). Live preview with writing‑mode. Internationalize your CSS.
Toggle contain: strict, content, paint, layout and see how it affects rendering. Understand isolation for faster pages.
Manipulate CSS values as typed objects using attributeStyleMap. Convert between CSSUnitValue, CSSMathSum, etc. Futuristic CSS‑in‑JS.
Based on home and destination time zones, suggests a light exposure/avoidance schedule to reduce jet lag. Educational tool, local only.
Paste your CSS and see rules sorted by specificity. Find overrides and potential collisions. Understand your cascade.
Access the Paint Timing API and display First Paint, First Contentful Paint, and Largest Contentful Paint times. Quick perf check.
Set an alarm relative to today's sunset (e.g., 30 minutes before). Perfect for evening routines. Uses geolocation (optional).
Create a frosted glass card with background blur, border glow, and shadow. Adjust intensity. Copy the CSS.
Enter a date and location (or use GPS) to see exact golden hour and blue hour times for perfect natural light.
Understand @layer by visually ordering style layers and seeing which rules win. Fix specificity battles. Modern CSS architecture.
Write slides in Markdown and instantly preview a web‑based presentation. Export as HTML. Pure frontend.
Enter your must volume and current Brix, TA, and pH to calculate additions of sugar, acid blend, or tannin. Standard winemaking formulas.
Connect to a BLE device and read its Battery Service characteristic. See the charge level in a gauge.
Mix sodium hypochlorite with water to get the correct % concentration for soft washing. Safety note.
Enter network name and password to generate a stylish printable card for visitors. Local, no data leak.
Drag tasks into a 2x2 grid (Urgent vs. Important or Impact vs. Effort). Visual decision aid. Local.
Estimate how long a battery will last given capacity (mAh/Wh) and load current. Also computes backup time for power banks. Quick and local.
Build a renovate.json file to automate dependency updates. Choose schedule, automerge, and package rules. Local.
Paste your stylesheet and get a clean list of all custom properties defined under :root. Copy the whole block. Local analysis.
See the current Service Worker registration, its state, and scope. Send 'skipWaiting' and update. PWA debug.
Calculate flour, water, starter amounts to achieve a target loaf hydration. Adjusts for starter hydration. Instant local calculation.
Estimate curing time for UV resin based on lamp wattage and layer thickness. Avoid sticky finishes.
See how extra monthly or lump‑sum payments reduce your mortgage term and total interest. Dynamic chart. All local calculation.
Enter total balance and limit to see utilization percentage. See how it affects credit score bands.
Click to get a random, unique superpower with a description. Perfect for character creation or daydreaming.
List all resources loaded by the current page and their detailed timing breakdown. In‑browser waterfall.
Calculate total work hours and pay from time-in/out entries. Supports overtime and breaks. Generate a printable timesheet. All local.
List your debts and compare the total interest paid using avalanche vs snowball methods. Pick the best strategy.