html

How to Disable a Default Color in Tailwind?

Tailwind is a famous CSS framework that offers a set of utility classes for styling web pages. One of the features of Tailwind is that it comes with a default color palette that is utilized to quickly apply colors to elements. However, sometimes users do not need default palette colors, or they want to use custom colors instead. In this situation, they can disable the default color in Tailwind.

This write-up will explain the method to disable the default color in Tailwind.

How to Disable a Default Color in Tailwind?

To disable the default color in Tailwind, it is required to override the default color palette by building a new color palette. After that, just include the required colors in it. Check out the below-provided steps for a better understanding:

Step 1: Configure Color Palette in the “tailwind.config.js” File

In the “tailwind.config.js” file, build a new color palette, and include only the required colors in it. For instance, we have included the “black”, “white”, “red”, “green” and “blue” colors:

const colors = require('tailwindcss/colors')

module.exports = {
content: ["./index.html"],
  theme: {
   colors: {
      black: colors.black,
      white: colors.white,
      red: colors.red,
      green: colors.green,
      blue: colors.blue,
    },  
  },
}

After specifying these colors, users will only be able to use these colors and all the other colors will be disabled.

Step 2: Use Colors in HTML Program

Now, use the required colors in the HTML program. Here, we have used some shades of “blue”, “yellow” and “pink” colors in our program:

<body>
  <h1 class="text-3xl text-blue-900 text-center">
    Hello world!
  </h1>
  <h2 class="text-2xl text-yellow-500 text-center">
    This is my first page.
  </h2>
  <h3 class="text-2xl text-pink-700 text-center">
    Linux Hint!
  </h3>
</body>

Step 3: View HTML Web Page

For verification, view the HTML web page to see if the disabled colors are working or not:

It can be seen that only the “blue” color which was defined in the new palette is working. While the rest of the colors including “yellow”, and “pink” are disabled and not working.

Conclusion

To disable a default color that is not being used in the project, it is required to build a new color palette in the “tailwind.config.js” file and just include the required colors in it. Then, use the colors in the HTML program and view the HTML web page to verify whether the disabled colors are working or not. This write-up has explained the method to disable the default color in Tailwind.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.