How to animate SVG polygon points?

svg animation
svg animate path d
svg polygon animation css
svg shape morphing css
svg frame animation
svg shape animation
svg shape animation codepen
animated svg background

I have created a line chart with SVG (polygon points) that I would like animated.

I would like the points to all start animating from the X axis, and when finished animating, the result to look like the following image.

It seems there is no simple way to achieve this, with the googling I have done. Any tips would be most appreciated, thanks.

What do you mean by "animating from the X axis" exactly? Do you mean start flat and grow upwards to this shape?

If so, it is actually very easy.

<svg viewBox="0 0 2040 352">
  <polygon points="" fill="red">
     <animate attributeName="points" dur="1s" fill="freeze"
              from="0,352, 550,352, 1240,352, 1592,352, 1880,352, 2040,352,
              to="0,292, 550,232, 1240,258, 1592,158, 1880,168, 2040,0,

How SVG Shape Morphing Works, Start with the most complicated shape. In this demo I'm going to morph from a star to a check. Make the next shape with those same points. Use the starting shape on the SVG shape element itself. Add an animation element that animates to the next shape. Trigger the animations as needed. SVG Polygon - <polygon> The <polygon> element is used to create a graphic that contains at least three sides. Polygons are made of straight lines, and the shape is "closed" (all the lines connect up).

I have done something in the past, this was however with a single control point of a SVG Bezier curve. However I think you can apply the same principle. I think you need to do the following steps

  1. Create an array with y values of the curves
  2. Create a jQuery animate function with a step method for each y value [jquery animate1

animate example

$({ n: 0 }).animate({ n: 40}, {
        duration: 1000,
        step: function(calculatedYValue, fx) {
            //update graphs with calculatedYValue
            console.log(parseInt(calculatedYValue), 10);   

Create and animate SVG polygons, Create and animate SVG polygons. Convert images to polygons. How the image will look before and after being run through Primitive. Paste your SVGs into the HTML. After creating the SVGs paste them into the body of the HTML. Extract polygon coordinates. Update the polygon arrays. Animate the polygons. The <polygon> element defines a closed shape consisting of a set of connected straight line segments. The last point is connected to the first point. For open shapes, see the <polyline> element.

This effect can be easily achieved with transform:scaley keyframe animation:

(javascript code in followind snippet is only for generating random svg polygon)

let n = 5, w = innerWidth - 20, h = innerHeight - 20;
let pts = Array(n).fill(0).map((_, i) => [(1+i)*(w/(n+1)), -Math.random()* h]);

document.body.innerHTML += `<svg width=${w} height=${h} viewbox=0,${-h},${w},${h} >
  <polygon points=0,0,${pts},${w},0 /></svg>`;
@keyframes grow {
  0%   {transform: scaley(0)}
  100% {transform: scaley(1)}

polygon {
  fill: #e45;
  animation: grow 0.5s forwards;

animating svg polygons, </ul> <svg class="svg-holder" viewBox="0 0 250 300" xmlns="http://www.w3. org/2000/svg" version="1.1"> <polygon fill="#414116" points="79,242 184,271� While animating SVG with CSS is easy and comfortable, CSS can’t animate all the SVG properties that are possible to animate. For instance, all the properties that define the actual shape of the elements aren’t possible to change or animate in CSS.

Animating SVG polygons by Nat on CodePen, Get the values of each points attribute in the polygons in that svg and put them into an object. Add this object to the to array. Animate the from� Do you like fabricJS? If you want it continue running and you do not mind tech related ads, please allow this website in your adblocker. ️ Thank You!

Path and polygon animation dimensions:width="250" y="250 , <svg width="250" height="250" xmlns=""> <polygon points="30 30 70 30 90 70 10 70" style="fill:#fcc; stroke:black"> <animate� The animateTransform element animates a transformation attribute on its target element, thereby allowing animations to control translation, scaling, rotation, and/or skewing.

How to animate svg polygon and lines, <path id="path1" d=" M 0, 0 L 200, 0"/> <polygon points="165 200, 215 200, 190 100 " style="fill:gray; stroke:black;"> <animateMotion dur="3s"� There isn’t just one way to animate SVG. There is the <animate> tag that goes right into the SVG code. There are libraries that help with it like Snap.svg or SVG.js.We’re going to look at another way: using inline SVG (SVG code right inside HTML) and animating the parts right through CSS.

  • Note, that <animate /> is not supported by Internet Explorer, not even by Edge (March 2019).
  • Great answer. Using JS to solve SVG problems is interesting for me.