{"id":190764,"date":"2014-12-14T13:34:04","date_gmt":"2014-12-14T20:34:04","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=190764"},"modified":"2017-01-07T07:40:38","modified_gmt":"2017-01-07T14:40:38","slug":"135-three-ways-animate-svg","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/video-screencasts\/135-three-ways-animate-svg\/","title":{"rendered":"#135: Three Ways to Animate SVG"},"content":{"rendered":"

Animating SVG is a bit unique in that there are three distinctly different ways you can approach animating it. <\/p>\n

<\/p>\n

1. Animating with CSS @keyframes<\/h3>\n

SVG elements can be targeted and styled with CSS. Meaning, you can apply animation through @keyframes. Like this:<\/p>\n

<svg viewBox=\"0 0 127.9 178.4\">\r\n  <path id=\"left-leg\" d=\"M37.6,138.8c0 ... \" \/>\r\n<\/svg><\/code><\/pre>\n
.left-leg {\r\n  fill: orange;\r\n  animation: dance 2s infinite alternate;\r\n}\r\n@keyframes dance {\r\n  100% {\r\n    transform: rotate(3deg);\r\n  }\r\n}<\/code><\/pre>\n

You might choose animating this way if…<\/h4>\n