Crispy provides a theme system that supports light and dark modes.
Themes are controlled through the data-seed-color-mode and data-seed-user-color-scheme attributes on HTML elements.
Learn the roles and differences of these two attributes, and how to set up global theme configuration and override themes for specific areas.
An attribute that represents the actual color scheme of the user's device. It has two values.
light: User's system is set to light mode
dark: User's system is set to dark mode
This value is only meaningful when data-seed-color-mode="system" and is automatically updated through the prefers-color-scheme media query.
<!-- Set to follow system settings, and user is currently using light mode --><html data-seed-color-mode="system" data-seed-user-color-scheme="light"></html>
Crispy CSS applies appropriate color tokens through the combination of both attributes:
/* When light mode is applied */:root,:root[data-seed-color-mode="system"][data-seed-user-color-scheme="light"],:root[data-seed-color-mode="light-only"],:root [data-seed-color-mode="light-only"] { /* Light mode color tokens */}/* When dark mode is applied */:root[data-seed-color-mode="system"][data-seed-user-color-scheme="dark"],:root[data-seed-color-mode="dark-only"],:root [data-seed-color-mode="dark-only"] { /* Dark mode color tokens */}
When you want to apply a different theme to a specific area or component, set data-seed-color-mode on that element with light-only, dark-only, or system values.
Sometimes components need to perform different actions based on the current theme settings.
In such cases, you can detect and use the data-seed-color-mode and data-seed-user-color-scheme attributes.
Here's an example of creating a custom hook to detect current theme information: