• Stars
    star
    491
  • Rank 89,636 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎨 The easiest way to create themes with Tailwind CSS.

Tailwind CSS Multi Theme

codecov Travis (.org) npm MIT License

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.

More Repositories

1

windmill-dashboard

📊 A multi theme, completely accessible, ready for production dashboard.
HTML
2,427
star
2

windmill-dashboard-react

❄ A multi theme, completely accessible, ready for production dashboard.
JavaScript
824
star
3

windmill-react-ui

🧩 The component library for fast and accessible development of gorgeous interfaces.
TypeScript
729
star
4

apenas-crie-websites

Algumas ideias para sites que você pode construir!
522
star
5

sharect

🔗 A lightweight JavaScript library to let users share their text selections to social networks.
JavaScript
215
star
6

tailwind-starter-kit

📚 A library of components and learning resource for Tailwind CSS.
JavaScript
153
star
7

aprenda-html5-css3

Códigos do curso de HTML5 e CSS3.
HTML
57
star
8

aprenda-html-css

Livro Aprenda HTML e CSS. Trabalho em andamento e sem exercicios.
53
star
9

codigos-canal

Códigos usados nos vídeos do canal no YouTube
JavaScript
41
star
10

tailwindcss-dropdown

🔽 Create accessible, JavaScript free dropdowns with Tailwind CSS. See live 👉
JavaScript
22
star
11

organico

Framework Responsivo CSS em português
CSS
14
star
12

pomodoro-timer

Vue
12
star
13

front-end-quiz

A non-exausting list of questions about front-end.
10
star
14

tailwindcss-markdown

Tailwind CSS plugin to style Markdown
JavaScript
10
star
15

a-simple-cms

That's it. A really simple and easy CMS, made with Node and Mongo.
JavaScript
6
star
16

yt-terminal-basico

Comandos básicos de linha de comando.
5
star
17

brasileirao-perf-2019

Estudo sobre a performance dos sites dos 20 clubes da série A do campeonato brasileiro de 2019
5
star
18

algorithms-in-javascript

Computer Science algorithms in JavaScript
JavaScript
5
star
19

ushor

URL Shortener
JavaScript
4
star
20

sublime-shortcuts

A list of Sublime Text 3 shortcuts
4
star
21

learn-html-css

WIP translation from https://github.com/estevanmaito/aprenda-html-css
4
star
22

tailwindcss-react-ui

Build complete UIs using Tailwind CSS. WIP. See live 👉
JavaScript
4
star
23

react-gradients

JavaScript
3
star
24

tailwindcss-boilerplate

A simple Tailwind CSS boilerplate
CSS
3
star
25

windmill-ui-site

JavaScript
3
star
26

react-native-boilerplate

My personal React Native Boilerplate
TypeScript
3
star
27

billie

Visual localized accessibility hints for websites
JavaScript
3
star
28

curso

Material e site do Curso de Framework CSS
HTML
3
star
29

react-redux-shopping-cart

Work in progress
JavaScript
2
star
30

human-regex

Simple, human readable Regular Expressions for JavaScript
2
star
31

library-boilerplate

General JavaScript library boilerplate
JavaScript
2
star
32

docurin-release

Release for https://docurin.com
2
star
33

react-component-library

JavaScript
1
star
34

billie-ext

[WIP] Accessibility error detector
JavaScript
1
star
35

pomodoro

TypeScript + React version of my Pomodoro Timer
TypeScript
1
star
36

node-backend-boilerplate

Node, MongoDB, Express, Redis, Docker, Jest, Nodemailer
JavaScript
1
star
37

error-logger

JavaScript
1
star
38

old-blog

Too much to do, too much to write... the worst blog in the web
1
star
39

div-to-img

A wip playground. for now
JavaScript
1
star
40

blog

JavaScript
1
star