Techtales.

How to create gradient borders with Tailwind CSS
TT
Techtales Team✨Author
Aug 8, 2025
3 min read

How to create gradient borders with Tailwind CSS

00

For a long time now, I have been admiring gradient borders and researching how to create such borders with minimal code and without any external packages. Gradient borders are a great way to add visual interest and depth to a website. They can highlight important elements, create a sense of movement, or simply make a website look more stylish. Here are few steps to create gradient borders with Tailwind CSS.

Gradient Borders in CSS | CSS-Tricks

Step 1: Create a parent container

Create a div element, add rounded-3xl and p-px utilities to it.  Note that you can use another border radius utility and padding; visually, the padding will be seen as the border's size.

Step 2: Add a gradient background to the container

If your card is over a blurry background, you should play with opacity to get a better look.

Example: from-gray-950/40

Step 3: Create another container inside the parent container

Step 4: Add a custom border radius to the child container

As the parent container has a border radius, you have to add some to the child container to get a perfect rounded border.

Use this formula to get the border radius of the child container :

Child container border radius = (parent container border radius) - (parent container padding).

For example, if the parent container border radius is 10px and the parent container padding is 2px, then the child container border radius would be 10px - 2px = 8px.

To calculate, use the css calc function to get the exact border radius of the child container.

You can calculate in your head, but using the 'calc' function allows you to obtain the result even when you don't know the padding or border radius of the parent container, as may be the case when using css variables.

The CSS rule should look like this :

Arbitrary value

Use an arbitrary value to apply the formula to the Tailwind CSS rounded utility.

Step 5: Add Content to Your Card

Now add some content to your child container so it can appear in the DOM.

Here is the result, note I tweaked the colors to pink-500 via purple-500, to yellow-400 to make the gradient more visible.

Congratulations, you've created gradient borders using Tailwind CSS!

You can use this technique to craft a variety of gradient borders with different colors, gradient styles, and border radii. This approach adds visual interest and depth to your website while maintaining a clean, modern aesthetic.

Bonus

You can now advance your gradient border by adding some animation to make it come alive. This would require adding some keyframes to the parent component for the animations. The code could look something like this:

Now the next step is to add CSS keyframes into our globals.css file. This would require defining them in the layer utilities.

Now you can brag about this to your friends and feel confident as a frontend developer.

0
0