A Tailwind CSS plugin that generates shorthand utilities for light and dark mode color pairs.
npm install tailwind-light-dark
# or
yarn add tailwind-light-darkAdd the plugin to your app.css or app.postcss file:
@import "tailwindcss";
@plugin 'tailwind-light-dark';
/* Required: Make dark mode class based */
@custom-variant dark (&:where(.dark, .dark *));
/* ... */Add the plugin to your tailwind.config.js file:
// tailwind.config.js
module.exports = {
darkMode: 'class', // This is required
// ...
plugins: [
require('tailwind-light-dark')({ version = 3 }),
// ...
],
}Then use the generated utilities in your HTML:
<!-- Background colors -->
<div class="bg-red-200-700">
<!-- This will be red-200 in light mode and red-700 in dark mode -->
</div>
<!-- Text colors -->
<div class="text-blue-300-900">
<!-- This will be blue-300 in light mode and blue-900 in dark mode -->
</div>
<!-- White/black shortcuts -->
<div class="bg-white-black text-black-white">
<!-- White background with black text in light mode -->
<!-- Black background with white text in dark mode -->
</div>This plugin generates the following utility types:
bg-{color}-{lightShade}-{darkShade}- Background colorstext-{color}-{lightShade}-{darkShade}- Text colorsborder-{color}-{lightShade}-{darkShade}- Border colorsdecoration-{color}-{lightShade}-{darkShade}- Text decoration colorsoutline-{color}-{lightShade}-{darkShade}- Outline colorsshadow-{color}-{lightShade}-{darkShade}- Box shadow colorsinset-shadow-{color}-{lightShade}-{darkShade}- Inset box shadow colorsring-{color}-{lightShade}-{darkShade}- Ring shadow colorsinset-ring-{color}-{lightShade}-{darkShade}- Inset ring shadow colorsaccent-{color}-{lightShade}-{darkShade}- Accent colorscaret-{color}-{lightShade}-{darkShade}- Caret colorsfill-{color}-{lightShade}-{darkShade}- SVG fill colorsstroke-{color}-{lightShade}-{darkShade}- SVG stroke colorsfrom-{color}-{lightShade}-{darkShade}- Gradient from colorsto-{color}-{lightShade}-{darkShade}- Gradient to colors
The plugin also provides convenient white/black pairs:
bg-white-black/bg-black-whitetext-white-black/text-black-whiteborder-white-black/border-black-whitefill-white-black/fill-black-whitestroke-white-black/stroke-black-whitefrom-white-black/from-black-whiteto-white-black/to-black-white
MIT
This plugin was heavily inspired by SkeletonUI. They provide light-dark color pairings for their own themed colors (e.g. primary-100-900, secondary-600-400, surface-950-50, etc.) and I wanted light-dark pairings available for every tailwind color.