DEV Community

Cover image for Multiples mode using same as dark mode class by Tailwindcss
Thang Truong
Thang Truong

Posted on

2 1

Multiples mode using same as dark mode class by Tailwindcss

Tailwind - A utility-first CSS framework
Dark mode is supported in Tailwindcss, you can see it here

However, you want to edit your own mode. Please follow these steps

  1. Installation tailwind to your project (docs here)

  2. After complete install, you can see taiwind.config.js (cjs)

  3. Create a themes folder to store your own themes

  4. Create files your-theme.js in folder themes and insert this code

const plugin = require("tailwindcss/plugin");

const themeName = "your-theme-name"; // this is name of your custom theme (dark, red, light, ...)

module.exports = plugin(function ({ addVariant, e }) {
  addVariant(`${themeName}`, ({ modifySelectors, separator }) => {
    modifySelectors(({ className }) => {
      return `.${themeName} .${e(`${themeName}${separator}${className}`)}`;
    });
  });
});
Enter fullscreen mode Exit fullscreen mode
  1. Open tailwind.config.js, import your custom theme by option plugin
/** @type {import('tailwindcss').Config} */

module.exports = {
  darkMode: "class",
  content: ["./src/**/*.{astro,html,js,jsx,md,mdx,ts,tsx}"],
  theme: {
    extend: {},
  },
  plugins: [require("./themes/your-theme.js")], // edit the path if it doesn't match your project structure
};
Enter fullscreen mode Exit fullscreen mode
  1. Finish, you can use your custom same as dark mode in Tailwind
<h1 class="text-red-500 dark:text-white red:text-red-800 orange:text-orange-700">Hello</h1>
Enter fullscreen mode Exit fullscreen mode

NOTE: Don't forget to add a class to the html tag if you want the attribute to be enabled <html lang="en" class="red">

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more