Back to the library

Progress arc

A determinate progress ring driven by stroke-dashoffset, starting at twelve o’clock where the eye expects it. Use it when you actually know the percentage; for unknown waits, an indeterminate spinner is the honest choice. The arc eases in and out because it is travelling across the ring, not entering the screen.

progresssvgloadingdeterminate

The source

A complete HTML document. Paste it into an empty .html file and it plays — no stylesheet, script, font, or image to fetch.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Progress arc</title>
    <style>
      :root {
        --ivory: #faf9f5;
        --slate: #141413;
        --clay: #d97757;
        --oat: #e3dacc;
        --gray-500: #87867f;
      }

      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      body {
        min-height: 100vh;
        display: grid;
        place-items: center;
        background: var(--ivory);
        font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
        color: var(--slate);
      }

      .arc {
        position: relative;
        width: 108px;
        height: 108px;
      }

      .arc svg {
        width: 100%;
        height: 100%;
        /* -90deg so the arc starts at twelve o'clock, where a progress ring is
           read from. Static rotation, not animated. */
        transform: rotate(-90deg);
      }

      .arc circle {
        fill: none;
        stroke-linecap: round;
        stroke-width: 5;
      }

      .arc .track {
        stroke: var(--oat);
      }

      /* Determinate progress: stroke-dashoffset is the only property that maps
         to "how far along", and it is paint-only. ease-in-out because the arc is
         travelling across the ring, not entering the screen. */
      .arc .fill {
        stroke: var(--clay);
        stroke-dasharray: 302;
        animation: fill-arc 3.6s infinite;
      }

      .arc .label {
        position: absolute;
        inset: 0;
        display: grid;
        place-items: center;
        font-size: 15px;
        font-variant-numeric: tabular-nums;
        color: var(--gray-500);
        letter-spacing: -0.01em;
      }

      @keyframes fill-arc {
        0% {
          stroke-dashoffset: 302;
          animation-timing-function: cubic-bezier(0.77, 0, 0.175, 1);
        }
        55%,
        88% {
          stroke-dashoffset: 0;
        }
        96%,
        100% {
          stroke-dashoffset: 302;
          opacity: 0;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        .arc .fill {
          animation: none;
          stroke-dashoffset: 76;
        }
      }
    </style>
  </head>
  <body>
    <div class="arc" role="img" aria-label="Progress">
      <svg viewBox="0 0 108 108">
        <circle class="track" cx="54" cy="54" r="48" />
        <circle class="fill" cx="54" cy="54" r="48" />
      </svg>
      <span class="label">Uploading</span>
    </div>
  </body>
</html>