Open In App

SVG <mpath> Element

The <mpath> is the sub element for the <animateMotion> element that provides the ability to reference an external <path> element as the definition of a motion path.

Syntax:



<animateMotion attributes="" >
   <mpath xlink:href=""/>
</animateMotion>


Attributes:

Example:






<!DOCTYPE html> 
<html
    
    <body
  
        <svg width="30%" height="30%"  viewBox="0 0 500 300"
             xmlns="http://www.w3.org/2000/svg"
             xmlns:xlink="http://www.w3.org/1999/xlink" >
  
            <rect x="1" y="1" width="495" height="295"
                fill="none" stroke="green" stroke-width="3"/>
  
        <!-- Drawing the outer edge of the motion path in green, along
             with three circles at the start, middle and end -->
  
            <path id="geeksforgeeks" d="M100,250 C 100,50 400,50 400,250"
                  fill="none" stroke="green" stroke-width="8.02"/>
  
            <circle cx="100" cy="250" r="18.64" fill="green"/>
            <circle cx="250" cy="100" r="18.64" fill="green"/>
            <circle cx="400" cy="250" r="18.64" fill="green"/>
  
        <!-- Make a triangle which will be moved about the motion path. -->
            <path d="M-25,-12.5 L25,-12.5 L 0,-87.5 z"
                  fill="yellow" stroke="green" stroke-width="8.02">
  
        <!-- Defining the motion path animation -->
                <animateMotion dur="3s" repeatCount="indefinite" rotate="auto" >
                    <mpath xlink:href="#geeksforgeeks"/>
                </animateMotion>
            </path>
        </svg>
  
    </body
</html>

Output:

Browsers Supported: The following browsers are supported by this SVG element:


Article Tags :