Site icon Puneet Sharma – Freelance Web Developer

How to know the length of the path in SVG?

How to know the length of the path in SVG to animate it with the stroke offset method?

Well, the answer is very simple. Just use the following JavaScript and update its selector to that of the path you want to calculate the length of. Check the length value in the browser console area.

<script>
    var path = document.getElementById("line7");
    var length = path.getTotalLength();
    console.log(length);
</script>
Exit mobile version