In this article, we will know HTML SVG Basics, & their implementation through the examples. SVG stands for Scalable Vector Graphics. It basically defines vector-based graphics in XML format. SVG graphics do NOT lose any quality if they are zoomed or resized. Every element and every attribute in SVG files can be animated.
Advantages of SVG: Advantages of using SVG over other image formats (like JPEG and GIF) are:
- SVG images can be created and edited with any text editor.
- SVG images can be searched, indexed, scripted, and compressed.
- SVG images are scalable.
- SVG images can be printed with high quality at any resolution.
Differences between HTML SVG and HTML Canvas:
- If attributes of an SVG object are changed, the browser can automatically re-render the shape whereas Canvas is rendered pixel by pixel. In canvas, once the graphic is drawn, it is forgotten by the browser.
- SVG is resolution independent whereas CANVAS is resolution-dependent.
- SVG supports event handlers whereas CANVAS doesn’t have support for event handlers.
Example 1: In this example, We create an SVG line in HTML.
Example 2: Drawing A SVG Circle in HTML
Example 3: Drawing A SVG Rectangle in HTML
Example 4: Drawing A SVG Rounded Rectangle in HTML
Example 5: Drawing A SVG Star in HTML
Example 6: Drawing A Logo in HTML using SVG
- Google Chrome 4.0
- Internet Explorer 9.0
- Firefox 3.0
- Opera 10.1
- Safari 3.2