Dark mode
If you use Sass to develop, there is a predefined placeholder selector for dark mode, this file is in /scss/helpers/_dark-mode.scss, in this file the %dark-mode selector is defined you can create your selectors by extending it.
Here is an example of a dark mode selector:
html.dark {
@extend %dark-mode;
}
Now if the <html> tag has the .dark class, the dark mode will be applied.
Note that you should extend this selector as <html> tag because it changes CSS variables that are defined as the :root.
Sass does not let you @extend a selector from inside @media, so something like @media (prefers-color-scheme: dark) { :root { @extend %dark-mode; } } stops the build with an error. If you want to follow the user's system theme, use the CSS variables below instead.
Without Sass
The compiled CSS files do not include a dark theme, because %dark-mode is a Sass placeholder and placeholders are only printed when you extend them. That is not a problem, dark mode is just a set of CSS variables, so you can write it yourself.
Here is what %dark-mode does, it is also the way to detect automatically if users prefer dark theme with CSS @media feature:
@media (prefers-color-scheme: dark) {
:root {
/* Lighter primary colors */
--flatify__color-blue-primary: #3ebcf7;
--flatify__color-green-primary: #71d428;
--flatify__color-yellow-primary: #ffe326;
--flatify__color-orange-primary: #ffa626;
--flatify__color-red-primary: #ff6666;
--flatify__color-pink-primary: #ff98d7;
--flatify__color-purple-primary: #ca7bff;
--flatify__color-accent-primary: #3ebcf7;
--flatify__color-success-primary: #71d428;
--flatify__color-info-primary: #3ebcf7;
--flatify__color-warning-primary: #ffa626;
--flatify__color-danger-primary: #ff6666;
/* Increase brightness */
--flatify__hover-brightness: 110%;
/* Background color */
--flatify__bg-color: #10191c !important;
--flatify__bg-color-dark: #141f23 !important;
--flatify__bg-color-darker: #263b43 !important;
--flatify__bg-color-darkest: #385661 !important;
--flatify__color-light-light: #141f23 !important;
--flatify__color-light-primary: #10191c !important;
--flatify__color-light-dark: #263b43 !important;
/* Text color */
--flatify__txt-color: #f1f4f7;
--flatify__txt-color-dark: #ced9e3;
--flatify__txt-color-darker: #809cb6;
--flatify__txt-color-inverted: #141f23;
--flatify__color-dark-light: #f1f4f7;
--flatify__color-dark-primary: #ced9e3;
--flatify__color-dark-dark: #809cb6;
}
}
Want a toggle button instead? Put the same variables inside html.dark { ... } and add or remove the .dark class with JavaScript.
The primary colors above are 15% lighter than the defaults, so they stay readable on a dark background. If you changed the palette, lighten your own colors the same way.