Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="progress-container" data-value="92">
  <svg class="progress-bar" id="svg" width="120" height="120" viewPort="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <circle class="progress-meter" r="48" cx="60" cy="60" fill="transparent" stroke-width="20" stroke-dashoffset="0"></circle>
    <circle class="progress-value" r="48" cx="60" cy="60" fill="transparent" stroke-width="20" stroke-dashoffset="0" stroke-dasharray="301.59"></circle>
  </svg>
  <span>0%</span>
</div>

<div class="progress-container" data-value="73">
  <svg class="progress-bar" id="svg" width="120" height="120" viewPort="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <circle class="progress-meter" r="48" cx="60" cy="60" fill="transparent" stroke-width="20" stroke-dashoffset="0"></circle>
    <circle class="progress-value" r="48" cx="60" cy="60" fill="transparent" stroke-width="20" stroke-dashoffset="0" stroke-dasharray="301.59"></circle>
  </svg>
  <span>0%</span>
</div>

<div class="progress-container" data-value="21">
  <svg class="progress-bar" id="svg" width="120" height="120" viewPort="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <circle class="progress-meter" r="48" cx="60" cy="60" fill="transparent" stroke-width="20" stroke-dashoffset="0"></circle>
    <circle class="progress-value" r="48" cx="60" cy="60" fill="transparent" stroke-width="20" stroke-dashoffset="0" stroke-dasharray="301.59"></circle>
  </svg>
  <span>0%</span>
</div>
              
            
!

CSS

              
                .progress-container {
  --hue: 0;
  
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-container + .progress-container {
  margin-top: 1rem;
}


.progress-container span {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.progress-bar {
  transform: rotate(-90deg);
}

.progress-bar circle {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1.5s ease-in-out;
  transition-delay: 1s;
  stroke: hsl(0, 0%, 40%);
}

.progress-bar .progress-value {
  stroke: hsl(var(--hue), 100%, 60%);
  stroke-dashoffset: 301.59;
}

/**
 * Style the pen
 */
html,
body {
  background-color: #393939;
  color: #fff;
  font: 100%/1.7 "Open Sans", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

#control {
  margin-top: 2rem;
}
              
            
!

JS

              
                // Cache all progress bars as NodeList
const progressBars = document.querySelectorAll('.progress-container');

const animateValue = (selector, start, end, duration) => {
  var obj = selector;
  var range = end - start;

  // no timer shorter than 50ms (not really visible any way)
  var minTimer = 50;
  
  // calc step time to show all interediate values
  var stepTime = Math.abs(Math.floor(duration / range));
  
  // never go below minTimer
  stepTime = Math.max(stepTime, minTimer);
  
  // get current time and calculate desired end time
  var startTime = new Date().getTime();
  var endTime = startTime + duration;
  var timer;

  function run() {
    var now = new Date().getTime();
    var remaining = Math.max((endTime - now) / duration, 0);
    var value = Math.round(end - remaining * range);
    obj.innerHTML = value + "%";
    if (value == end) {
      clearInterval(timer);
    }
  }

  var timer = setInterval(run, stepTime);
  run();
}

const progress = (value) => {
  var progress = value / 100;
  var dashoffset = circumference * (1 - progress);

  progressValue.style.strokeDashoffset = dashoffset;

  animateValue(valueContainer, 0, dataValue, 1500);
}

// Iterate over each progress bar
for (var el of progressBars) {
  var dataValue = el.getAttribute('data-value');
  var progressValue = el.querySelector('.progress-value');
  var valueContainer = el.querySelector('span');
  
  valueContainer.dispatchEvent(new Event('change'));

  var radius = progressValue.getAttribute("r");
  
  var circumference = 2 * Math.PI * radius;
  
  progressValue.style.strokeDasharray = circumference;
  progress(dataValue);
}
              
            
!
999px

Console