AI CSS Animations

Transparent Gradient Border

A rotating gradient border with a see-through middle, so it sits on any background or image. A mask with mask-composite exclude cuts the inside out of a conic-gradient layer.

Also known as: gradient border transparent background css, gradient border without background, see-through gradient border.

See-through middle

HTML

<div class="bdr-transparent-gradient-border">See-through middle</div>

CSS

@property --bdr-transparent-gradient-border-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.bdr-transparent-gradient-border {
  --c: var(--bdr-color, #3b82f6);
  font-size: var(--bdr-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 15em;
  height: 8.5em;
  border-radius: 1em;
  font-family: system-ui, sans-serif;
  font-weight: 600;

}
.bdr-transparent-gradient-border::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 0.2em;
  border-radius: inherit;
  background: conic-gradient(from var(--bdr-transparent-gradient-border-a), var(--c), color-mix(in oklch, var(--c), #ec4899 80%), var(--c));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
  animation: bdr-transparent-gradient-border-spin 4s linear infinite;
}
@keyframes bdr-transparent-gradient-border-spin {
  to { --bdr-transparent-gradient-border-a: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
  .bdr-transparent-gradient-border, .bdr-transparent-gradient-border *, .bdr-transparent-gradient-border::before, .bdr-transparent-gradient-border::after, .bdr-transparent-gradient-border *::before, .bdr-transparent-gradient-border *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<div class="relative grid h-[8.5em] w-[15em] place-items-center rounded-2xl font-semibold">
  <div class="pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] p-[3px] [-webkit-mask-composite:xor] [mask-composite:exclude] [mask:linear-gradient(#000_0_0)_content-box,linear-gradient(#000_0_0)]">
    <div class="absolute inset-[-100%] animate-spin bg-[conic-gradient(#3b82f6,#ec4899,#3b82f6)] [animation-duration:4s]"></div>
  </div>
  See-through middle
</div>

Customizing this snippet

  • Color: set --bdr-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --bdr-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar border animations