Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw an arrow in SVG?

Tags:

html

svg

I need to make it flexible. It can be some type of lines and arrows on the end of lines.

So, I decided to create two SVG objects: lines and an arrowhead.

How to draw an arrowhead on the end or beginning of the line?

My line is:

<svg width="500" height="100">
  <line x1="0" y1="80" x2="100" y2="20" stroke="black" />
</svg>

1 Answers

You can use defs and path — http://jsfiddle.net/jxtfeqag/

<svg>
  <defs>
    <marker 
      id='head' 
      orient="auto" 
      markerWidth='3' 
      markerHeight='4' 
      refX='0.1' 
      refY='2'
    >
      <path d='M0,0 V4 L2,2 Z' fill="black" />
    </marker>
  </defs>

  <path
    id='arrow-line'
    marker-end='url(#head)'
    stroke-width='4'
    fill='none' stroke='black'  
    d='M0,0, 80 100,120'
  />
        
</svg>
like image 123
mr. pc_coder Avatar answered Dec 06 '25 06:12

mr. pc_coder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!