How to create gradient borders with tailwindcss
Tags: webdev, tailwindcss, webdesign
Published: 2023-07-10 16:08:20


![tailus gradient borders cover](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0v6iqr9yx2t535axwpji.jpg)


Gradient borders are a great way to add visual interest and depth to a website. They can be used to highlight important elements, create a sense of movement, or simply make a website look more stylish.

Here are few steps to to create gradient borders with tailwindcss.

## 1. Create a container

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

```
<div class="rounded-3xl p-px"></div>
```

## 2. Add a gradient background to the container

```
<div class="rounded-3xl p-px bg-gradient-to-b from-gray-200 to-transparent"></div>
```

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

Example : `from-gray-950/40`

## 3. Create an other container inside the parent container

```
<div class="rounded-3xl p-px bg-gradient-to-b from-gray-200 to-transparent">
    <div class="bg-gray-50 p-10">

    </div>
</div>
```

## 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 : **

```
.child-container {
  border-radius: calc(3.5rem - 1px);
}
```

### Arbitrary value

Use an arbitrary value to apply the formula to the tailwind css `rounded` utility.

```
<div class="rounded-3xl p-px bg-gradient-to-b from-gray-200 to-transparent">
    <div class="bg-gray-50 p-10 `rounded-[calc(1.5rem-1px)]`">

    </div>
</div>
```

## 5. Add content to your card

```
<div class="rounded-3xl p-px bg-gradient-to-b from-gray-200 to-transparent">
    <div class="bg-gray-50 p-10 rounded-[calc(1.5rem-1px)]">
      <p class="text-gray-700 dark:text-gray-300">I absolutely 
love Tailus! The component blocks are beautifully designed and easy to use, which makes creating a great-looking website a breeze.
      </p>

      <div class="mt-8 flex gap-4 items-center">
        <img class="h-12 w-12 rounded-full" src="https://pbs.twimg.com/profile_images/1599029039297077249/p0znhFdE_400x400.jpg" alt="" />
        <div>
          <h3 class="text-lg font-medium text-gray-700 dark:text-white">Oketa Fred</h3>
          <span class="text-sm tracking-wide text-gray-600 dark:text-gray-400">Fullstack Developer</span>
        </div>
      </div>
    </div>
</div>
```

Congratulations, you've created gradient borders using tailwind css!

You can use this technique to create a variety of gradient borders, with different colors, gradients, and border radius. This can be a great way to add visual interest and depth to your website.

Tell me what you think about this in the comments