SVG animation: animate an SVG icon with CSS and JavaScript

Опубликовано: 27 Февраль 2026
на канале: pmCodingTutorials
29,680
892

In this SVG animation tutorial with CSS and JavaScript we will animate an SVG heart when the user clicks on it.
We will achieve this using various CSS animations and properties such as stroke-dasharray and stroke-dashoffset.

To view the final SVG animation and to get the source code visit:
https://codepen.io/patriciamolnar/pen...

An example of how the SVG animation could look when added to a social media site:
https://codepen.io/patriciamolnar/ful...

Icons and further information:
heroicons: https://heroicons.com/
stroke-dasharray: https://developer.mozilla.org/en-US/d...
stroke-dashoffset: https://developer.mozilla.org/en-US/d...
stroke-linejoin: https://developer.mozilla.org/en-US/d...
stroke-linecap: https://developer.mozilla.org/en-US/d...

Found this tutorial useful? Buy me a coffee: https://www.buymeacoffee.com/patricia... 😊

For more CSS animations tutorials, check out my other videos:
1) CSS Animations: Neon Glow with SVG text:
   • CSS Animation:  Animated Neon Glow with SV...  

2) Interactive CSS background animation:
   • CSS background animation tutorial - code i...  

3) CSS Text animation:
   • CSS Text Animation - Animate letters in fr...  

Connect with me on social media:
Twitter:   / pmcoding  
Instagram:   / pmcoding  
CodePen: https://codepen.io/patriciamolnar

My website: https://pmcoding.co.uk
Any questions, email me at [email protected]