Updated 5 min read

Create an Animated Border with Tailwind CSS

Add a dynamic touch to your designs with an animated border in Tailwind CSS, using conic-gradient and CSS animations for an eye-catching effect.

Example of animated borders with Tailwind CSS in a dark design, featuring a vibrant color gradient background.

Goal: build a rotating gradient “border” in Tailwind CSS v4 using a conic gradient, a padded wrapper and a CSS @property angle animation — with live examples you can copy.

Prerequisites: basic HTML/CSS, a Tailwind v4 project (or CDN play area), and comfort reading utility classes. You do not need a design system.

Advertisement

The native border property cannot animate its colour the way most people want. The reliable trick is to animate a parent background and let the child cover the middle, so the visible ring is really just padding.

This method might seem complex if you rarely touch CSS gradients, but the moving parts are few: conic gradient, padding thickness, and one custom property for the angle.

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.
  • Radial Gradient: Radial gradient from a central point outward.
  • Conic Gradient: Conic gradient around a central point, creating a “wheel” effect.

For our animated border, we’ll use conic gradient, as it allows us to create a spinning effect.

Implementing the Animated Border

<div
  class="w-full max-w-lg bg-conic/[from_0deg] from-white to-white dark:from-black via-green-400 dark:to-black  rounded-2xl p-px"
>
  <div class="p-10 rounded-2xl bg-transparent">
    <p class="text-white text-center font-semibold ">
      Parent container background
    </p>
  </div>
</div>

Parent container background




If we add a background to the child container, we achieve the border effect:

<div
  class="w-full max-w-lg bg-conic/[from_0deg] from-white to-white dark:from-black via-green-400 dark:to-black rounded-2xl p-px"
>
  <!-- Parent container -->
  <div class="p-10 rounded-2xl dark:dark:bg-zinc-900 bg-mint-50">
    <!-- Child container -->
    <p class="text-white text-center font-semibold">
      By adding a background to the child container, we achieve the border effect
    </p>
  </div>
</div>

By adding a background to the child container, we achieve the border effect

Adding Animation with @property

We’ll use @property to define a custom property that will allow us to animate the border:

@property --border-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

Then, we create the animation with @keyframes and add it to the Tailwind CSS theme:

@theme {
  --animate-rotate-border: border-rotate 3s linear infinite;
  @keyframes border-rotate {
    to {
      --border-angle: 360deg;
    }
  }
}

Now we’ll implement it in our parent container classes:

<div
  class="w-full max-w-lg bg-conic/[from_var(--border-angle)] from-white to-white dark:from-black via-green-400 dark:to-black animate-rotate-border rounded-2xl p-px"
>
  <div class="p-10 rounded-2xl bg-transparent">
    <p class="text-white text-center font-semibold">
      Animated parent container background
    </p>
  </div>
</div>

Animated parent container background


This is how it looks with a background in our content

Adjusting the Border Thickness

By modifying the padding, we can control the border thickness:

<div
  class="w-full max-w-lg bg-conic/[from_var(--border-angle)] from-white to-white dark:from-black via-green-400 dark:to-black animate-rotate-border rounded-2xl p-[3px]"
>
  <div class="p-10 rounded-2xl dark:bg-zinc-900 bg-zinc-50">
    <p class="text-white text-center font-semibold">
      By adjusting the padding we can "increase the border thickness"
      <br />
      <code>p-[3px]</code>
    </p>
  </div>
</div>

By adjusting the padding we can "increase the border thickness"
p-[3px]

Customizing the Gradient

In Tailwind CSS, we can control the position of the gradient colors:

  • from-* → Starting color of the gradient.
  • via-* → Intermediate color.
  • to-* → Final color of the gradient.

We can also adjust the color positions, for example:

<div
  class="w-full max-w-lg bg-conic/[from_var(--border-angle)] from-white to-white dark:from-black via-green-400 dark:to-black from-30% to-60% animate-rotate-border rounded-2xl p-px"
>
  <div class="p-10 rounded-2xl bg-transparent">
    <p class="text-white text-center font-semibold">
      By adjusting the color positions we achieve a different effect
      <br />
      <code>from-30% to-60%</code>
    </p>
  </div>
</div>

By adjusting the color positions we achieve a different effect
from-30% to-60%

Final Result

I’ll make some small adjustments, changing the from and to colors to achieve a more natural effect. Also, I’ll use a 1px padding.

<div
  class="w-full max-w-lg bg-conic/[from_var(--border-angle)] from-green-200/20 via-green-400 to-green-200/20 from-30% to-60% animate-rotate-border rounded-2xl p-px"
>
  <div class="p-10 rounded-2xl dark:bg-zinc-900 bg-zinc-50">
    <p class="text-white text-center font-semibold">
      This is the final result
    </p>
  </div>
</div>

This is the final result

Common mistakes

  1. Animating the child instead of the parent — the gradient must live on the outer element; the inner element only masks the centre with a solid (or opaque) background.
  2. Forgetting @property — without registering --border-angle as an <angle>, many browsers will not interpolate the animation smoothly.
  3. Using a transparent child background — you will see the full spinning disc, not a border.
  4. Heavy blur + huge elements everywhere — decorative borders are cheap; pairing them with large animated blurs on low-end phones is not.
  5. Ignoring prefers-reduced-motion — offer a static gradient when users ask for reduced motion.
@media (prefers-reduced-motion: reduce) {
  .animate-rotate-border {
    animation: none;
  }
}

Troubleshooting

SymptomLikely causeFix
No spin@property or @keyframes not loaded into the Tailwind themeConfirm the @theme block is in a CSS file Tailwind processes
Full square of colourChild has no opaque backgroundSet bg-* on the inner div
Border too thick/thinPadding on the parentUse p-px, p-[2px], p-[3px]…
Works in Chrome onlyOlder Safari quirks with @propertyCheck current Safari support; provide a static fallback

When I use this

I use animated borders sparingly: featured CTAs, pricing highlight cards, or a single hero accent. On content-heavy pages (like articles on this site) static borders read better and cost less attention.

Final checklist

  • Parent has conic gradient + animation
  • Child has opaque background and smaller radius if needed
  • Thickness controlled by parent padding
  • Reduced-motion fallback
  • Contrast checked in light and dark themes

That is the whole technique: mask a spinning conic gradient with padding. Once it clicks, customising colours and speed becomes the fun part — without turning every card on the page into a casino sign.