Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <svg class="ring-chart" viewBox="0 0 40 40" class="donut">
  <!-- rotate <g>roup -90deg to start chart rings at top, and set default stroke-width -->
  <g fill="none" class="ring-chart__ring-group" stroke-width="3" transform="rotate(-90)">
    <!-- <circle>s use a radius of 15.91549430918954 to get a circumference of 100px (c = 2πr) for easy percentages -->
    <circle class="ring-chart__ring" stroke="#003f5c" stroke-dasharray="25 100" style="" cx="20" cy="20" r="15.91549430918954"></circle>
    <!-- add style="--rotation: startingRotationPoint;" to start a ring at a specific rotation, fallback is 0 -->
    <circle class="ring-chart__ring" stroke="#bc5090" stroke-dasharray="30 100" style="--rotation: 25;" cx="20" cy="20" r="15.91549430918954"></circle>
    <circle class="ring-chart__ring" stroke="#ffa600" stroke-dasharray="45 100" style="--rotation: 55;" cx="20" cy="20" r="15.91549430918954"></circle>
  </g>
</svg>
              
            
!

CSS

              
                body {
  height: 100vh;
  display: grid;
  place-content: center;
}

.ring-chart {
  max-width: 600px;
  width: 80vw;
  // will unhide in JS, this eliminates FOUC 
  visibility: hidden;
}

.ring-chart__ring-group,
.ring-chart__ring {
  // needed for SVG coordinate system based on viewBox of 0 0 40 40
  transform-origin: 20px 20px;
}

.ring-chart__ring {
  // sets individule circle's rotations. Can be excluded on single-ring charts  
  transform: rotate(calc(360deg * var(--rotation, 0) / 100));
  transition: .333s stroke-width ease;
  cursor: pointer;
  
  &:hover {
    stroke-width: 4;
  }
}


              
            
!

JS

              
                // unhide to eliminate FOUC, since we are animating .from with GSAP
gsap.set('.ring-chart',  { autoAlpha: 1 })

// make array of all the rings for easy looping
const rings = gsap.utils.toArray(".ring-chart__ring")

// setup timeline. using ease: 'none' to creat a smooth overall draw effect
const tl = gsap.timeline({ paused: true, defaults: { ease: 'none' } })

rings.forEach((ring) => {
  // get stroke-dasharray number to use as duration
  const string = gsap.getProperty(ring, "strokeDasharray");
  const sDAArray = string.split(', ')
  const percentValue = parseInt(sDAArray[0], 10); 
  
  // get current rotation to use as absolute timing offset
  const offset = gsap.getProperty(ring, '--rotation')
  
  // add each ring to timeline at specific absolute time value  
  tl.from(ring, {
    strokeDasharray: "0 100",
    duration: percentValue / 100,
  }, (offset / 100))
  
})

// animate timeline progress to acheive a global ease on entire antimation.
// repeated with yoyo to show effect in CodePen without refreshing
gsap.to(tl, { 
  progress: 1, 
  delay: .2, 
  duration: 1.75, 
  ease: 'power3', 
  // repeat: -1, 
  // yoyo: true, 
  repeatDelay: 2 
})
              
            
!
999px

Console