AI CSS Animations

Two Tone Border

Two colors share the border and play tug of war: the split drifts round while each side keeps winning and losing ground. One @property angle turns it and a second percentage moves the split.

Also known as: two color border css, half and half border css, split color border.

Two tone

HTML

<div class="bdr-two-tone-border">Two tone</div>

CSS

@property --bdr-two-tone-border-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@property --bdr-two-tone-border-s {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 50%;
}
.bdr-two-tone-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;
  --two: color-mix(in oklch, var(--c), #f59e0b 85%);
  box-sizing: border-box;
  border: 0.22em solid transparent;
  background:
    linear-gradient(color-mix(in srgb, var(--c) 10%, #0b0f19), color-mix(in srgb, var(--c) 10%, #0b0f19)) padding-box,
    conic-gradient(from var(--bdr-two-tone-border-a), var(--c) 0 calc(var(--bdr-two-tone-border-s) - 3%), var(--two) calc(var(--bdr-two-tone-border-s) + 3%) 97%, var(--c)) border-box;
  color: #f1f5f9;
  animation:
    bdr-two-tone-border-turn 8s linear infinite,
    bdr-two-tone-border-tug 2.4s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
@keyframes bdr-two-tone-border-turn {
  to { --bdr-two-tone-border-a: 360deg; }
}
@keyframes bdr-two-tone-border-tug {
  from { --bdr-two-tone-border-s: 28%; }
  to   { --bdr-two-tone-border-s: 72%; }
}

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

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