Tailwind CSS Dark Mode
Installation
npm install tailwindcss-dark-mode --save-dev
Add the plugin to the plugins
array in your Tailwind configuration.
plugins: [
require('tailwindcss-dark-mode')()
]
Usage
Styles generated by this plugin are only used if the selector is applied to the <html>
element. How you do that is up to you. prefers-dark.js
is provided as an option, which is a simple script that enables dark mode based on the user's system theme.
Available Variants
Variants for dark mode are based on Tailwind's own variants...
dark
dark-hover
dark-focus
dark-active
dark-disabled
dark-group-hover
dark-focus-within
dark-even
dark-odd
dark-placeholder
... and are used in the same way.
<div class="bg-white dark:bg-black">
<p class="text-black dark:text-white">
My eyes are grateful.
<a ... class="text-blue-300 hover:text-blue-400 dark:text-blue-700 dark-hover:text-blue-600">
Learn more
</a>
</p>
</div>
Enabling Variants
As with existing variants such as hover
and focus
, variants for dark mode must be enabled in your Tailwind configuration for any utilities that need them.
variants: {
backgroundColor: ['dark', 'dark-hover', 'dark-group-hover', 'dark-even', 'dark-odd'],
borderColor: ['dark', 'dark-disabled', 'dark-focus', 'dark-focus-within'],
textColor: ['dark', 'dark-hover', 'dark-active', 'dark-placeholder']
}
Please note: This is only a simple demonstration for how dark variants are enabled and how they could be used. The variants provided by this plugin are not replacements for Tailwind's own variants, they are to be used in addition to them. For example, anywhere you would enable dark-hover
, you should also enable hover
.
Changing the Selector
By default, .mode-dark
is used as the selector for dark mode. You can change this by adding the darkSelector
key to the theme
section in your Tailwind configuration.
theme: {
darkSelector: '.mode-dark'
}
Don't forget to also change the selector in prefers-dark.js
if you are using it.
PurgeCSS
If you are using PurgeCSS, you should either add the selector to the whitelist
array...
whitelist: ['mode-dark']
... or add prefers-dark.js
to the content
array.
content: [
'**/*.js',
'./node_modules/tailwindcss-dark-mode/prefers-dark.js',
'./or/your/own/prefers-dark.js'
]
Otherwise, PurgeCSS will assume that any classes related to dark mode should be removed, as the selector is only applied when the page is loaded.
feat(*) Allow using class name via config
Hey - thanks for this plugin, super helpful!
I'm integrating with an existing project which already handles dark-mode with a different class name on the body. Rather than adding another one with
mode-dark
, I've patched these changes locally to pass in a different class name.Thanks,
Bump browserslist from 4.14.5 to 4.16.6
Bumps browserslist from 4.14.5 to 4.16.6.
Changelog
Sourced from browserslist's changelog.
Commits
6fe3614
Release 4.16.6 version33ebac9
Update dependencies2128170
Add support for npm-shrinkwrap files alongside package-lock (#595)7cc2aed
Release 4.16.5 version27e4afd
Update dependencies1013a18
Fix version RegExpb879a1a
Use Node.js 16 on CIbd1e9e0
Fix ReDoS (#593)209adf9
Release 4.16.4 version3e2ae3b
Fix typesDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
Bump lodash from 4.17.20 to 4.17.21
Bumps lodash from 4.17.20 to 4.17.21.
Commits
f299b52
Bump to v4.17.21c4847eb
Improve performance oftoNumber
,trim
andtrimEnd
on large input strings3469357
Prevent command injection through_.template
'svariable
optionDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
Fix dark mode typography not working (#30)
Fix #30
Add Adam Wathan's dark mode variant can working on typography. This dark mode variant base features the same this tailwindcss-dark-mode package.
Bump lodash from 4.17.15 to 4.17.19
Bumps lodash from 4.17.15 to 4.17.19.
Release notes
Sourced from lodash's releases.
Commits
d7fbc52
Bump to v4.17.192e1c0f2
Add npm-package1b6c282
Bump to v4.17.18a370ac8
Bump to v4.17.171144918
Rebuild lodash and docs3a3b0fd
Bump to v4.17.16c84fe82
fix(zipObjectDeep): prototype pollution (#4759)e7b28ea
Sanitize sourceURL so it cannot affect evaled code (#4518)0cec225
Fix lodash.isEqual for circular references (#4320) (#4515)94c3a81
Document matches* shorthands for over* methods (#4510) (#4514)Maintainer changes
This version was pushed to npm by mathias, a new releaser for lodash since your current version.
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
Bump eslint-utils from 1.3.1 to 1.4.2
Bumps eslint-utils from 1.3.1 to 1.4.2.
Commits
4e1bc07
1.4.2e4cb014
π add null test230a4e2
1.4.108158db
π fix getStaticValue security issue587cca2
π fix getStringIfConstant to handle literals correctlyc119e83
π fix getStaticValue to handle bigint correctly531b16f
π 1.4.0276303d
β upgrade rollupcb518c7
π fix hasSideEffect false negativeaac472e
π fix isParenthesized had false positive on ImportExpression (fixes #1)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot ignore this [patch|minor|major] version
will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
watch for changes to dark mode
Enhancement to watch for changes to dark mode after site has been initialized. This way, should a user change their preference (whether it be manual, based on system time settings, etc), the site will automatically update accordingly.
Bump lodash from 4.17.11 to 4.17.14
Bumps lodash from 4.17.11 to 4.17.14.
Commits
be87d30
Bump to v4.17.14.a6fe6b1
Rebuild lodash and docs.e371828
Bump to v4.17.13.357e899
Rebuild lodash and docs.fd9a062
Bump to v4.17.12.e77d681
Rebuild lodash and docs.629d186
Update OpenJS references.2406eac
Fix minified build.17a34bc
Fix test bootstrap for core build.53838a3
Fix tests in older browsers.Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot ignore this [patch|minor|major] version
will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
Rename dark-placeholder: to dark: for placeholderColor and new dark-divide for divideColor
Previous update
dark-placeholder
was suggested to text-color utility.I renamed the variant return value from
dark-placeholder:
todark:
and if used on placeholderColor, it will produce shorter and .mode-dark compatible placeholder's color.