AI CSS Animations

Move in a Circle

Travels round a small circle at an even speed and stays upright the whole way. The trick is rotate, translate, then rotate back the same amount in one transform, so only the position turns.

Also known as: css animation circular path, orbit animation css, rotate around a point.

Orbit

HTML

<div class="kfa-move-in-a-circle">Orbit</div>

CSS

.kfa-move-in-a-circle {
  --c: var(--kfa-color, #3b82f6);
  font-size: var(--kfa-size, 16px);
  display: grid;
  place-items: center;
  width: 5.5em;
  height: 5.5em;
  border-radius: 1em;
  background: var(--c);
  color: #fff;
  font-family: system-ui, sans-serif;
  font-weight: 700;
  box-shadow: 0 0.6em 1.4em -0.6em color-mix(in srgb, var(--c) 70%, transparent);
  animation: kfa-move-in-a-circle-orbit 3s linear infinite;
}
@keyframes kfa-move-in-a-circle-orbit {
  from { transform: rotate(0deg) translateX(1.6em) rotate(0deg); }
  to { transform: rotate(360deg) translateX(1.6em) rotate(-360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .kfa-move-in-a-circle, .kfa-move-in-a-circle *, .kfa-move-in-a-circle::before, .kfa-move-in-a-circle::after, .kfa-move-in-a-circle *::before, .kfa-move-in-a-circle *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --kfa-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --kfa-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 keyframe animations