npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tailwindcss-multi-theme

v1.0.4

Published

The easiest way to create themes with Tailwind CSS.

Downloads

3,778

Readme

Tailwind CSS Multi Theme

Most theme plugins ask too much from the start. If you know how to create a simple page with default Tailwind, you already know how to use this theme plugin.

🧪 See it live

🧱 See examples

💿 Install

npm install tailwindcss-multi-theme

In tailwind.config.js add themeVariants to the theme property, with the value(s) of your theme(s), and require the plugin. That's it.

module.exports = {
  theme: {
    themeVariants: ['dark']
  },
  variants: {
    // just add dark to any variant that you want to style
  },
  plugins: [require('tailwindcss-multi-theme')],
}

It will create a set of classes based on your variants and expect a class .theme-<the name of your themeVariants> at the top of your HTML document.

themeVariants: ['dark'] would activate its classes under .theme-dark.

🚀 Usage

👉 themeVariants is the only configuration option.

It expects an array of strings, so there is no limit to how many themes you can create. Want a dark and a neon theme (you don't need to specify your default)? Do this:

module.exports = {
  theme: {
    themeVariants: ['dark', 'neon']
  },
  variants: {
    // just add dark and neon to any variant that you want to style
  },
  plugins: [require('tailwindcss-multi-theme')],
}

You can now place the class .theme-dark or .theme-neon at the top of your HTML (eg. on body or an enclosing div) and just write classes like:

dark:bg-gray-900 dark:text-gray-300

But just this won't work. You need to specify what variants of your theme you want, in your variants:

...
variants: {
  backgroundColor: ['responsive', 'hover', 'focus', 'dark'],
  textColor: ['responsive', 'hover', 'focus', 'dark'],
},
...

What if you need to style the hover, focus or any other variant on some specific theme?

...
variants: {
  backgroundColor: ['responsive', 'hover', 'focus', 'dark', 'dark:hover', 'dark:focus'],
  textColor: ['responsive', 'hover', 'focus', 'dark', 'dark:hover', 'dark:focus'],
},
...

The same way you would write it in HTML (dark:hover:bg-red-100) you write in your variants settings, just by adding a : before the variant.

So, if you're already using focus-within, it would be called dark:focus-within, considering your theme is called dark.

Using inside CSS with @apply

UPDATE: Tailwind CSS ^1.7.0 (Use @apply with variants and other complex classes) now supports this syntax:

.btn {
  @apply border-4 border-gray-300 dark:border-dark-gray-600;
}

Another way, (and the only way for Tailwind CSS prior to v1.7.0), is the following.

If you're more into writing some CSS using @apply, you could try the code below. Note that it needs nesting support, and you can find more about it in the official docs.

input {
  @apply bg-gray-300;
}

input:focus {
  @apply bg-white;
}

/**
 * Place your theme styles inside .theme-<your-theme>
 * In this case, we have themeVariants: ['dark']
 */
.theme-dark {
  input {
    @apply bg-gray-800;
  }

  input:focus {
    @apply bg-gray-500;
  }
}

If you want to avoid nesting for some reason, this syntax is also perfectly valid:

.theme-dark input {
  @apply bg-gray-800;
}

.theme-dark input:focus {
  @apply bg-gray-500;
}

How to automatically apply the theme based on user's preferences?

a.k.a prefers-color-scheme

You should use prefers-dark.js to detect if it is supported. If so, the theme will be applied automatically. Place it in the top of the head of your HTML (execute early to reduce the flash of light theme).

By the way, you can check one of the examples

If you're looking for a CSS only approach, you could give tailwindcss-theming a try.

❓ Why another theme plugin?

I'll tell you the truth. I'm lazy. I created this plugin for people that, like me, just want to keep writing Tailwind CSS as always, with the same familiar syntax, no theme files, no extensive obligatory docs read to know how to color my backgrounds.

It just prepends your theme variable to the good old Tailwind classes.