Facts About SVG
- The main challenging drawing program for SVG is FLASH.
- Flash depends on other technologies like XSL and DOM. In that case, SVG plays a role like an open source drawing program.
- SVG images are scalable, zoomable and can be printed with high quality at any resolution.
- SVG files are complete XML files, so it can be easily developed with the help of HTML and Basic XML knowledge.
- SVG can be created with any text editor, but Inkscape is a more convenient drawing program for it.
How to Code SVG?
An SVG image begins with <svg> tag and closing with </svg> tag. Make sure all the elements in SVG can be closed properly because it is written in XML.
Example 1 - DRAW A CIRCLE
Let’s draw a circle with SVG element,
Firstly, to draw any shape we need to create an SVG element with two attributes: width and height.
- <html>
- <head>
- <title> Draw a Circle Using SVG</title>
- </head>
- <body>
- <svg width=”1050” height=”1050”>
- </svg>
- </body>
- </html>
Still there is nothing going to be applied on an output screen.
Add a <circle> tag,
- <html>
- <head>
- <title> Draw a Circle Using SVG</title>
- </head>
- <body>
- <svg width="2050" height="2050">
- <circle cx= "80" cy="80" r="50" fill="blue" stroke="red"/></svg>
- </body>
- </html>
Note
In SVG file there is every element and any attribute can be animated.
In this code, there are a few attributes which are new for us,
- cx:x coordinate, cy:y coordinate, r:radius , fill, stroke
- cx: it defines the center of the circle from the right of the screen
- cy: it defines the center of the circle from the top the screen
- r: it is the radius of the circle
- fill: it is used to color the circle
- stroke: it is used to give an outline to the circle.
Output

Note
With the use of<ellipse> element, we can create an oval shape.
Example 2 - DRAW A RECTANGLE
In this example, we will see two more attributes of the rectangle shape: width and height. It defines the width and height of the rectangle.
Add a <rect> tag,
Let’s draw a rectangle with SVG element,
- <html>
- <head>
- <title> Draw a Rectangle Using SVG</title>
- </head>
- <body>
- <svg width="2050" height="2050">
- <rect width="250" height="100" fill="blue" stroke="red"/></svg>
- </body>
- </html>
Output
Example 3 - DRAW A ROUNDED RECTANGLE
In the previous example, we have seen attributes of rectangle shapes: width and height. It defines the width and height of the rectangle. Now, we will see two more attributes: rx: horizontal radius and ry: vertical radius, to draw rounded corners of the rectangle.
Add a <rect> tag,
Let’s draw a rounded rectangle with SVG element,




Ankur MistryPosted Nov 21, 2019, 10:42 AM
Good stuff, thanks for sharing
Onkar SharmaPosted Oct 19, 2019, 12:43 AM
Nice article, and nice explanation of new feature of html5... ..