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

              
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" data-value="40">
  <path class="bg" d="M21.5 114.5c18-16 1-74 49-44s65 48 74 38 61-13 17-39-91-55-83-31-23 43 1 63 40 36 53 46 17 16 27 4" fill="none" stroke="#ccc" stroke-miterlimit="10"/>
  <path class="meter" d="M21.5 114.5c18-16 1-74 49-44s65 48 74 38 61-13 17-39-91-55-83-31-23 43 1 63 40 36 53 46 17 16 27 4" fill="none" stroke="#09c" stroke-dasharray="512" stroke-dashoffset="512" stroke-miterlimit="10"/>
</svg>
              
            
!

CSS

              
                body {
  display: grid;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

svg path {
  stroke-width: 10px;
  stroke-miterlimit: round;
  transition: stroke-dashoffset 850ms ease-in-out;
}
              
            
!

JS

              
                console.clear();

const meters = document.querySelectorAll('svg[data-value] .meter');

meters.forEach( (path) => {
  // Get the length of the path
  let length = path.getTotalLength();
  // console.log(length) once and hardcode the stroke-dashoffset and stroke-dasharray in the SVG if possible or set it dynamically
  // path.style.strokeDashoffset = length;
  // path.style.strokeDasharray = length;

  // Get the value of the meter
  let value = parseInt(path.parentNode.getAttribute('data-value'));
  // Calculate the percentage of the total length
  let to = length * ((100 - value) / 100);

  // Trigger Layout in Safari hack https://jakearchibald.com/2013/animated-line-drawing-svg/
  path.getBoundingClientRect();
  // Set the Offset
  path.style.strokeDashoffset = Math.max(0, to);  
});


              
            
!
999px

Console