Draw a Polyline in HTML5 SVG



SVG stands for Scalable Vector Graphics and is a language for describing 2D-graphics and graphical applications in XML and the XML is then rendered by an SVG viewer. Most of the web browsers can display SVG just like they can display PNG, GIF, and JPG.

To draw a polygon in HTML SVG, use the SVG <polyline> element. The <polyline> element is to create a shape that consists of straight lines. The points attribute is the x and y coordinates for each corner.

Example

You can try to run the following code to learn how to draw a polyline in HTML5 SVG:

<!DOCTYPE html>
<html>
   <head>
      <style>
         #svgelem {
            position: relative;
            left: 20%;
            -webkit-transform: translateX(-20%);
            -ms-transform: translateX(-20%);
            transform: translateX(-20%);
         }
      </style>
      <title>HTML5 SVG Polyline</title>
   </head>

   <body>
      <h2>HTML5 SVG Polyline</h2>
      <svg id="svgelem" width="300" height="300" xmlns="http://www.w3.org/2000/svg">
         <polyline points="0,0 0,20 20,20 20,40 40,40 40,60" fill="red" />
      </svg>
   </body>
</html>

Output

Updated on: 2023-11-22T04:21:13+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements