Tailwind Border Color: Explained and Demonstrated

In this article, we’ll take a closer look at Tailwind border color classes with examples and how they can be used in your web development projects.

Tailwind CSS is a popular CSS framework that offers a range of classes to quickly style your HTML elements.

One of the key features of Tailwind CSS is its comprehensive set of border color classes.

Tailwind Border Colors



Tailwind Border Color

Tailwind border color of an element can be set using the border color class.

In Tailwind CSS, this class accepts multiple values, with each value represented by a class. Alternatively, in normal CSS, the border-color property is used.

Syntax

<element class="border-{color}"></element>

Tailwind Border Color classes

The border color of an element can be specified using the “border-{color}” class in Tailwind CSS.

This class accepts a range of values that can be used to define the color of the border.

Here are some of the most commonly used border color classes in Tailwind CSS:

  1. border-transparent : This class sets the border color to transparent. This is useful when you want to hide the border of an element.
  2. border-current : This class sets the border color to the same color as the text or background color of the element. This is useful when you want to create an outline around the element that blends in with the content.
  3. border-white : This class sets the border color to white. This is useful when you want to create a border that stands out against a dark background.
  4. border-black : This class sets the border color to black. This is useful when you want to create a border that stands out against a light background.
  5. border-{color}-50 : This class sets the border color to a shade of the specified color. The number “50” can be replaced with any number from 100 to 900 to get a different shade of the color. For example, “border-blue-100” will give you a lighter shade of blue than “border-blue-900”.
  6. border-blue-50 : This class will result in a blue border.
  7. border-red-50 : This class sets the border color to red. This is useful when you want to create a border that stands out against a light background.
  8. border-indigo-50 : This class sets the border color to indigo. This is useful when you want to create a border that stands out against a light background.
  9. border-yellow-50 : This class sets the border color to yellow. This is useful when you want to create a border that stands out against a dark background.
  10. border-green-50 : This class sets the border color to green. This is useful when you want to create a border that stands out against a dark background.
  11. border-purple-50 : This class sets the border color to purple. This is useful when you want to create a border that stands out against a light background.
  12. border-pink-50 : This class will result in a pink border.
Note: You can alter the color values between 50-900, but the jump in value should always be 100 after 100 (eg. 100,200,300,etc).

To use a Tailwind border color class, simply add it to the HTML element that you want to style.

The following example portrays the use of bg-transparent and bg-black classes:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head><body class="text-center mx-4"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-semibold my-2">Border Color Class in Tailwind CSS</p> <div class="mx-14 bg-green-200 grid grid-rows-2 grid-flow-col gap-2 text-center p-2 font-semibold"> <p class="border-2 border-transparent p-2"> border-transparent </p> <p class="border-2 border-black p-2"> border-black </p> </div> </body> </html>

You can also combine multiple border classes to create more complex border styles.

The border-current and border-white classes are demonstrated in the example below.

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head><body class="text-center mx-4"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-semibold my-2">Border Color Class in Tailwind CSS</p> <div class="mx-14 bg-green-200 grid grid-rows-2 grid-flow-col gap-2 text-center p-2 font-semibold"> <p class="border-2 border-current text-red-500 p-2"> border-current </p> <p class="border-2 border-white p-2"> border-white </p> </div> </body> </html>

The focus of this example is on utilizing the border-gray-400 and border-blue-700 class.

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center mx-4"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-semibold my-2">Border Color Class in Tailwind CSS</p> <div class="mx-14 bg-green-200 grid grid-rows-2 grid-flow-col gap-2 text-center p-2 font-semibold"> <p class="border-2 border-gray-400 p-2"> border-gray-400 </p> <p class="border-2 border-blue-700 p-2"> border-blue-700 </p> </div> </body> </html>

In this example border-red-500 and border-indigo-700 classes are utilized:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center mx-4"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-semibold my-2">Border Color Class in Tailwind CSS</p> <div class="mx-14 bg-green-200 grid grid-rows-2 grid-flow-col gap-2 text-center p-2 font-semibold"> <p class="border-2 border-red-500 p-2"> border-red-500 </p> <p class="border-2 border-indigo-700 p-2"> border-indigo-700 </p> </div> </body> </html>

Let’s implement border-purple-500 and border-yellow-400 classes in Tailwind for a better understanding:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center mx-4"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-semibold my-2">Border Color Class in Tailwind CSS</p> <div class="mx-14 bg-green-200 grid grid-rows-2 grid-flow-col gap-2 text-center p-2 font-semibold"> <p class="border-2 border-purple-500 p-2"> border-purple-500 </p> <p class="border-2 border-yellow-400 p-2"> border-yellow-400 </p> </div> </body> </html>

This example makes use of border-green-600 and border-pink-500 classes for illustration:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center mx-4"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-semibold my-2">Border Color Class in Tailwind CSS</p> <div class="mx-14 bg-green-200 grid grid-rows-2 grid-flow-col gap-2 text-center p-2 font-semibold"> <p class="border-2 border-green-600 p-2"> border-green-600 </p> <p class="border-2 border-pink-500 p-2"> border-pink-500 </p> </div> </body> </html>

Conclusion

Tailwind border color classes provide a convenient way to add borders to HTML elements with a wide range of colors and styles.

By using these classes, you can quickly create a variety of border styles without having to write custom CSS.

Whether you want to create a subtle outline or a bold border, Tailwind CSS has a class to help you achieve the look you want.

We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *