How to add tailwind CSS colors to your project

blogImage

By Emmanuel Chinonso

Technical Writer

Last updated: 13 May 2024

Tailwind Colors

Adding Tailwind colors to your project is an effortless way to elevate your design and create a captivating user experience. In this article, we will explore the diverse range of Tailwind CSS colors available and guide you on incorporating your own custom colors into Tailwind CSS for your project.

Table of content

  • Understanding Tailwind Colors
  • Integrating Tailwind CSS Colors
  • Default Tailwind colors Palette
  • Applying Tailwind Background color
  • Applying Tailwind Text Color
  • Customizing Tailwind Colors
  • Conclusion

Understanding Tailwind Colors

Tailwind CSS provides a built-in color system, offering a diverse range of colors. Each color comes with a series of shades for variation. The naming convention follows a simple {color}-{number} pattern, where {color} represents the base color (e.g., "red"). {number} indicates the shade, with "500" being the base shade, followed by darker shades like "red-600," "red-700," and lighter shades like "red-400," "red-300."

Integrating Tailwind CSS Colors

Installing Tailwind CSS To get started, you need to install Tailwind CSS. Open your project's terminal and run the following command:

bash
npm install tailwindcss

After installing tailwindcss, tailwind default colors will be available for you to use.

Default Tailwind Color Palette

Tailwind CSS offers a comprehensive range of colors to choose from for your project. Tailwind CSS comes with an appealing default color palette right out of the box, ensuring your designs look impressive. Take a look at some of the default Tailwind colors you can experiment with:

Gray
colors.coolGray
50
#F9FAFB
100
#F3F4F6
200
#E5E7EB
300
#D1D5DB
400
#9CA3AF
500
#6B7280
600
#4B5563
700
#374151
800
#1F2937
900
#111827
Red
colors.red
50
#FDF2F2
100
#FDE8E8
200
#FBD5D5
300
#F8B4B4
400
#F98080
500
#F05252
600
#E02424
700
#C81E1E
800
#9B1C1C
900
#771D1D
Yellow
colors.amber
50
#FDFDEA
100
#FDF6B2
200
#FCE96A
300
#FACA15
400
#E3A008
500
#C27803
600
#9F580A
700
#8E4B10
800
#723B13
900
#633112
Green
colors.emerald
50
#F3FAF7
100
#DEF7EC
200
#BCF0DA
300
#84E1BC
400
#31C48D
500
#0E9F6E
600
#057A55
700
#046C4E
800
#03543F
900
#014737
Blue
colors.blue
50
#EBF5FF
100
#E1EFFE
200
#C3DDFD
300
#A4CAFE
400
#76A9FA
500
#3F83F8
600
#1C64F2
700
#1A56DB
800
#1E429F
900
#233876
Indigo
colors.indigo
50
#F0F5FF
100
#E5EDFF
200
#CDDBFE
300
#B4C6FC
400
#8DA2FB
500
#6875F5
600
#5850EC
700
#5145CD
800
#42389D
900
#362F78
Purple
colors.violet
50
#F6F5FF
100
#EDEBFE
200
#DCD7FE
300
#CABFFD
400
#AC94FA
500
#9061F9
600
#7E3AF2
700
#6C2BD9
800
#5521B5
900
#4A1D96
Pink
colors.pink
50
#FDF2F8
100
#FCE8F3
200
#FAD1E8
300
#F8B4D9
400
#F17EB8
500
#E74694
600
#D61F69
700
#BF125D
800
#99154B
900
#751A3D

Applying Tailwind Background Colors

Tailwind CSS also offers a variety of utility classes for setting background colors. You can use the bg-{color} classes to apply background colors to different elements. For example, the bg-yellow-200 class sets the background color of an element to a light yellow shade, while the bg-gray-800 class applies a dark gray background color. By using these classes in conjunction with other utility classes, such as hover:bg-{color} for hover effects, you can create engaging and interactive user interfaces.

html
<div class ="relative rounded-xl overflow-auto p-8">
<div
class="flex flex-col gap-4 font-mono text-white text-sm text-center font-extrabold leading-6 bg-stripes-fuchsia rounded-lg"
>
<button class="bg-green-500 rounded-lg p-3">Green</button>
<button class="bg-purple-500 rounded-lg p-3">Purple</button>
<button class="bg-blue-500 rounded-lg p-3">Blue</button>
<button class="bg-yellow-500 rounded-lg p-3">Yellow</button>
<button class="bg-red-500 rounded-lg p-3">Red</button>
<button class="bg-pink-500 rounded-lg p-3">Pink</button>
</div>
</div>

The Tailwind Background colors are shown below.

Preview

Applying Tailwind Text Color

We can easily set the Tailwind colors text by using the text-[name], where the [name] represent the color name.

html
<div class="relative rounded-xl overflow-auto p-8">
<div
class="flex flex-col gap-4 font-mono text-white text-sm text-center font-extrabold leading-6 rounded-lg"
>
<p class="text-green-500 p-3">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<p class="text-purple-500 rounded-lg p-3">
Odit, corporis. Deserunt expedita numquam aliquid libero ea.
</p>
<p class="text-blue-500 p-3">
Eius sapiente quae adipisci tempora consequatur est dolorum praesentium repellat ipsum?
</p>
<p class="text-yellow-500 rounded-lg p-3">
Odit, corporis. Deserunt expedita numquam aliquid libero ea.
</p>
<p class="text-red-500 p-3">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<p class="text-pink-500 p-3">Odit, corporis. Deserunt expedita numquam aliquid libero ea.</p>
</div>
</div>

The Tailwind colors text Utilities

Preview

Lorem ipsum dolor sit amet consectetur adipisicing elit.

Odit, corporis. Deserunt expedita numquam aliquid libero ea.

Eius sapiente quae adipisci tempora consequatur est dolorum praesentium repellat ipsum?

Odit, corporis. Deserunt expedita numquam aliquid libero ea.

Lorem ipsum dolor sit amet consectetur adipisicing elit.

Odit, corporis. Deserunt expedita numquam aliquid libero ea.

Customizing Tailwind Colors

Step 1: Configuration After installing Tailwind CSS, you'll need to create a configuration file. Run this command:

bash
npx tailwindcss init

This command generates a tailwind.config.js file where you can customize your project's color palette.

Step 2: Customizing Colors

Open the tailwind.config.js file and customize or create your desired colors within the theme.extend.colors section, as shown below:

Code:

js
/** @type {import('tailwindcss').Config} */
export default {
theme: {
extend: {
// ...
colors: {
primary: {
blue: 'hsl(237, 63%, 64%)',
'very-light': 'hsl(240,78%, 98%)',
light: 'hsl(234, 14%,74%)',
normal: 'hsl(23, 13%, 33%)',
dark: 'hsl(232,13%,33%)',
},
},
},
},
plugins: [],
};

In the code snippet above, we have added a custom color palette under the colors section. You can define various shades and hues for each color. Feel free to adjust the values according to your preferences.

Step 3: Compile and Build the Styles

After configuring the tailwind.config.js file, you need to compile and build the styles to generate the customized Tailwind CSS file. Execute the following command in your terminal:

Code:

bash
npx tailwindcss build styles.css –o styles/tailwind.css.

This command compiles the styles and outputs the resulting CSS file in the styles/tailwind.css directory.

To showcase the custom colors, let's create a Tailwind colors project and add the following code snippet to an HTML file:

Code:

html
<div class="grid gap-2 items-center justify-center">
<div class="flex h-28 w-28 items-center justify-center rounded-lg bg-primary-blue m-4">
<p class="text-primary-very-light">Custom color</p>
</div>
</div>

Our webpage should look like the image

custom-colors

Conclusion

With Tailwind colors, you can effortlessly incorporate different colors into your projects using Tailwind CSS. You have flexibility to work with the default palette or define your own colors. Tailwind CSS simplifies the process of adding visual appeal to your web applications. To master Tailwind color, try experimenting with various hues and shades in your projects.

Build modern projects using Bootstrap 5 and Contrast

Trying to create components and pages for a web app or website from scratch while maintaining a modern User interface can be very tedious. This is why we created Contrast, to help drastically reduce the amount of time we spend doing that. so we can focus on building some other aspects of the project.

Contrast Bootstrap PRO consists of a Premium UI Kit Library featuring over 10000+ component variants. Which even comes bundled together with its own admin template comprising of 5 admin dashboards and 23+ additional admin and multipurpose pages for building almost any type of website or web app.
See a demo and learn more about Contrast Bootstrap Pro by clicking here.

Related Posts