Tailwindcss Theme Swapper screenshot

Tailwindcss Theme Swapper

Author Avatar Theme by Crswll
Updated: 27 May 2024
327 Stars

A helper for getting tailwind values into css custom properties and switching them between media queries and classes. You can try it out here: https://play.tailwindcss.com/Gt21fePNvv

Overview

The tailwindcss-theme-swapper is a tool that extends the Tailwind CSS framework by allowing users to customize their theme through CSS Custom Properties. This tool provides the ability to update and modify these custom properties using various selectors or media queries. The only requirement for using this tool is support for CSS Custom Properties, although it is worth noting that IE11 may have limited functionality unless supplemented with postcss-preset-env.

Features

  • Extend Tailwind config: The tailwindcss-theme-swapper allows users to extend their existing Tailwind CSS configuration with CSS Custom Properties.
  • CSS Custom Property updating: Users can update and modify CSS Custom Properties using any type of selector or media query.
  • Minimal installation: The tool can be easily integrated into a Tailwind project with minimal installation steps.

Installation

To install tailwindcss-theme-swapper, follow these steps:

  1. Add the package to your project using NPM or Yarn:
npm install tailwindcss-theme-swapper

or

yarn add tailwindcss-theme-swapper
  1. Import the plugin in your Tailwind config file (usually tailwind.config.js):
const themeSwapper = require('tailwindcss-theme-swapper');

module.exports = {
  // Your Tailwind config options here
  plugins: [
    // Other plugins
    themeSwapper,
  ],
};
  1. Customize your Tailwind CSS configuration by adding CSS Custom Properties to your tailwind.config.js file:
module.exports = {
  theme: {
    extend: {
      // Your existing Tailwind config options here
    },
    swapper: {
      // Define your CSS Custom Properties here
    },
  },
  variants: {
    // Your Tailwind variant options here
  },
  plugins: [
    // Other plugins
  ],
};
  1. Use the CSS Custom Properties in your CSS files or components as needed:
.example-element {
  background-color: var(--primary-color); /* Example use of a CSS Custom Property */
}

Please note that the above steps are a simplified guide and you may need to refer to the official documentation for more detailed instructions.

Summary

The tailwindcss-theme-swapper tool extends the functionality of the Tailwind CSS framework by allowing users to easily customize their theme using CSS Custom Properties. With minimal installation steps, users can add and update these properties to create unique and personalized designs. This tool is a valuable addition for Tailwind CSS users who want more flexibility and control over their project’s theme.