Custom Property Theme Light Dark
Implement a theming system using CSS custom properties with light and dark variants toggled by a data attribute.
Code
:root {
--color-bg: #ffffff;
--color-fg: #1a1a1a;
--color-accent: #0066cc;
--spacing-unit: 8px;
--radius: 6px;
}
[data-theme="dark"] {
--color-bg: #1a1a1a;
--color-fg: #f0f0f0;
--color-accent: #66b3ff;
}
.card {
background: var(--color-bg);
color: var(--color-fg);
border: 1px solid var(--color-accent);
border-radius: var(--radius);
padding: calc(var(--spacing-unit) * 2);
}Report a problem with this exampleOpens a pre-filled issue on GitHub.