What is SVG?
SVG is an image format for vector graphics. It literally means Scalable Vector Graphics
Why SVG does not lose clarity? (It scales to any size while maintaining quality)
An SVG image's data is stored as XML instead of pixels, and consists of components that can be scaled to any level without losing source quality.
Differences Between SVG and Canvas
SVG is a language for describing 2D graphics in XML.
Canvas draws 2D graphics, on the fly (with a JavaScript).
SVG is XML based, which means that every element is available within the SVG DOM. You can attach JavaScript event handlers for an element.
In SVG, each drawn shape is remembered as an object. If attributes of an SVG object are changed, the browser can automatically re-render the shape.
Canvas is rendered pixel by pixel. In canvas, once the graphic is drawn, it is forgotten by the browser. If its position should be changed, the entire scene needs to be redrawn, including any objects that might have been covered by the graphic
Example Code of a triangle:
<svg height="210" width="400">
<path d="M150 0 L75 200 L225 200 Z" />
</svg>
Explanation:
M = moveto
L = lineto
Z = closepath
Capital letters means absolutely positioned, lower cases means relatively positioned.
Source: W3 school
Top comments (0)