Change styles when using a dark theme.
With dark mode now being natively supported by most operating systems, it’s increasingly expected that your web apps offer a dark-themed version alongside the default appearance.
To simplify this process, Sfumato comes with a dark variant option, allowing you to customize your site’s appearance specifically for users who prefer dark mode.
Try the theme switcher widget above and watch how the buttons appear to switch positions as the color and text change based on the dark/light theme.
There are two Sfumato theme modes: system, and classes. You can configure this in your CSS file:
When setting --use-dark-theme-classes: true
Sfumato will generate classes that allow you to switch between normal, dark, and auto themes, where auto will switch based on the device (system) setting. These are placed on the <html> element and control the entire experience, or on separate elements to control components.
The theme class names are theme-dark and theme-auto and need to placed on the <html> or other containing elements:
When setting --use-dark-theme-classes: false
Sfumato will only switch to dark theme styles based on the device (system). This will happen automatically so no theme classes need to be put in your markup.
You can override the built-in dark variant with your own, like the one below that will cause dark theme styles to be triggered when the class dark is on an element or one of its ancestors:
Likewise, you could override the dark mode variant with one that uses a data attribute: