CSS Dot Swap Loader

Two colored dots that circle around each other and trade places, passing in front and behind.

  • dots
  • orbit
  • two colors
  • trade places
  • z-index
HTML
<div class="loader-swap" role="status" aria-label="Loading"></div>
CSS
.loader-swap {
  position: relative;
  width: 44px;
  height: 16px;
}

.loader-swap::before,
.loader-swap::after {
  content: "";
  position: absolute;
  top: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  animation: 1.1s ease-in-out infinite;
}

.loader-swap::before {
  left: 0;
  background: #f43f5e;
  animation-name: loader-swap-a;
}

.loader-swap::after {
  right: 0;
  z-index: 1;
  background: #06b6d4;
  animation-name: loader-swap-b;
}

@keyframes loader-swap-a {
  0% { transform: translateX(0); z-index: 2; }
  25% { transform: translateX(14px) scale(1.3); z-index: 2; }
  49% { z-index: 2; }
  50% { transform: translateX(28px); z-index: 0; }
  75% { transform: translateX(14px) scale(0.7); z-index: 0; }
  100% { transform: translateX(0); z-index: 0; }
}

@keyframes loader-swap-b {
  0% { transform: translateX(0); }
  25% { transform: translateX(-14px) scale(0.7); }
  50% { transform: translateX(-28px); }
  75% { transform: translateX(-14px) scale(1.3); }
  100% { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .loader-swap::before,
  .loader-swap::after { animation-duration: 3s; }
}

About this CSS Dot Swap Loader

This CSS Dot Swap Loader is 51 lines of pure CSS (1.1 KB) with no JavaScript and no dependencies. It uses keyframe animations, transforms and reduced-motion support. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #f43f5e
  • #06b6d4

How to use this dot swap loader

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .loader-swap class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback