--- layout: /src/layouts/MarkdownPostLayout.astro title: Create an Animated Border with Tailwind CSS author: Fernando López description: "Add a dynamic touch to your designs with an animated border in Tailwind CSS. Learn how to use conic-gradient and animations to achieve an impressive visual effect. 🚀✨" image: url: "/images/posts/animated-borders-tailwind.webp" alt: "Example of animated borders with Tailwind CSS in a dark design, featuring a vibrant color gradient background." pubDate: 2025-03-27 tags: [ "CSS", "Tailwind", "Animation", "Frontend", "UI" ] languages: ["tailwind", "html", ] --- The `border` property in CSS cannot be animated natively. However, we can simulate this effect by using a `div` with an animated background and placing the content inside a child element with `padding`, which will act as the "thickness" of the border. This method might seem complex for those who don't frequently work with CSS or frameworks like Tailwind CSS, but you'll see that it's not that difficult and the final result is quite satisfying. ## Types of Gradients in CSS To achieve our animated border effect, we need to know the different types of gradients in CSS: - **Linear Gradient:** Linear gradient along a specific direction. - [Documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient) - **Radial Gradient:** Radial gradient from a central point outward. - [Documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/radial-gradient) - **Conic Gradient:** Conic gradient around a central point, creating a "wheel" effect. - [Documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/conic-gradient) For our animated border, we'll use **conic gradient**, as it allows us to create a spinning effect. ## Implementing the Animated Border ```html
Parent container background
Parent container background
By adding a background to the child container, we achieve the border effect
By adding a background to the child container, we achieve the border effect
Animated parent container background
Animated parent container background
This is how it looks with a background in our content
By adjusting the padding we can "increase the border thickness"
p-[3px]
By adjusting the padding we can "increase the border thickness"
p-[3px]
By adjusting the color positions we achieve a different effect
from-30% to-60%
By adjusting the color positions we achieve a different effect
from-30% to-60%
This is the final result
This is the final result