CSS Circular Progress Bar

An SVG circular progress bar that draws itself with stroke-dashoffset and counts the percent in the middle.


CSS Circular Progress Bar


A circular progress bar is the right meter when the value is one number out of one hundred: a score, a quota, a battery, a single task. A linear bar is better when you are comparing several values. The ring puts the number in the middle, which is what people photograph and what screen readers should hear as text.

This version is an SVG circle. The circumference is the dash array. stroke-dashoffset hides the part of the stroke you have not “filled” yet. The demo eases three rings to 92, 64, and 41 and writes the same value beside each ring.

Pair it with the gradient progress bars when the layout is a list, and with the step progress indicator when the value is a sequence of named stages.

How the circular progress math works

For a circle with radius r, the circumference is 2 * π * r. In the demo r is 52, so the length is about 326.73.

Set both stroke-dasharray and the starting stroke-dashoffset to that length. The stroke is fully hidden. To show p percent, set the offset to circumference * (1 - p / 100). Rotate the circle -90deg so the stroke starts at 12 o’clock. stroke-linecap: round softens the leading end.

HTML

Two circles share a center. The first is the track. The second is the value. The visible number sits in a figcaption so it remains real text.

<figure>
  <svg viewBox="0 0 120 120" aria-hidden="true">
    <circle class="track" cx="60" cy="60" r="52"></circle>
    <circle class="value" data-value="92" cx="60" cy="60" r="52"></circle>
  </svg>
  <figcaption>
    <strong data-label>0</strong>
    <span>Accessibility score</span>
  </figcaption>
</figure>

aria-hidden on the SVG is deliberate. The figure caption is the accessible name of the value. If you omit the caption, put role="img" and an aria-label such as “Accessibility score 92 percent” on the SVG instead.

CSS

.track { fill: none; stroke: #e7e0d6; stroke-width: 8; }
.value {
  fill: none;
  stroke: #1c1917;
  stroke-width: 8;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 60px 60px;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
}

JavaScript

Ease the offset and the label together so the digit and the arc finish on the same frame. 1 - (1 - t) ** 3 is a cubic ease-out: fast start, soft landing, which reads as a meter settling.

const C = 2 * Math.PI * 52;
function paint(progress) {
  const target = 92;
  ring.style.strokeDashoffset = String(C * (1 - (target / 100) * progress));
  label.textContent = String(Math.round(target * progress));
}

Run paint from requestAnimationFrame for about 1.1 seconds. A replay button calls the same function. On a dashboard, call it when fresh data arrives.

Accessibility

Under reduced motion, set the offset to the final value in one frame and write the final number. The arc is a picture of a number you also print.

Do not use the ring as the only indication of a critical state. Color plus the printed percent covers that. Keep the track and the value stroke at least 3:1 against the page if the ring is the graphic, and keep the percent text at 4.5:1.

Questions about circular progress bars

Can I build a circular progress bar with CSS only?

Yes, with conic-gradient as a background and a mask that knocks out the center. That is shorter. The SVG stroke is easier to animate smoothly, easier to round at the tip, and easier to size without the center hole drifting. Use the conic version for a static badge. Use the stroke version when the value counts up.

How do I start the ring at the top?

SVG strokes start at 3 o’clock. transform: rotate(-90deg) with transform-origin at the circle’s center moves the start to 12 o’clock.

What radius should I use?

Pick the radius from the viewBox, then compute 2 * Math.PI * r in code instead of pasting a magic number you will forget to update. The demo hard-codes 326.73 because the radius is fixed at 52.