tailwindcss-colorize
A plugin for Tailwind CSS to colorize arbitrary elements using CSS filters. The most popular use case is to colorize single-color icons without altering the icon file directly.
See this CodePen for demo of the underlying method.
Requirements
This plugin requires Tailwind CSS v1.x.
Installation
npm install --save-dev tailwindcss-colorize
or
yarn add --dev tailwindcss-colorize
Usage
In your tailwind.config.js:
moduleexports = // … theme: colorize: // use any color defined in your theme, the following are taken from the default theme 'gray-500' 'teal-500' plugins: // … // … // …;
This would generate the following utility class:
And in your HTML you could use these classes like this:
For this to work, the icon color needs to be black. If it is not, you can use
the .blacken
utility class that is also generated like this: