Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 canvas element and svg

Tags:

Why do we need the html5 canvas element, when the same can be achieved through embedded svg?

like image 874
Stefano Borini Avatar asked Oct 30 '09 15:10

Stefano Borini


People also ask

What is SVG and Canvas in HTML5?

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.

Can I use SVG in Canvas?

To draw SVG onto canvas, you need to use SVG image. Firstly, use the <foreignObject> element which contains the HTML. After that, you need to draw the SVG image into the canvas.

Is SVG an HTML5 element?

<svg> elementIn HTML5, svg is a tag to produce svg elements. SVG is an inline-block level element. Inside svg element, number of methods for drawing text, circle, boxes, paths, and graphics images are created. SVG element of default height is 150 and the default width is 300.


1 Answers

SVG and canvas aren't really interchangeable technologies. SVG is a type of retained mode graphics where everything is drawn from a rather abstract model (the SVG document). Canvas on the other hand is a kind of immediate mode graphics, where there is no model and the client (JavaScript) must take care of redrawing, animations etc.

like image 174
foolip Avatar answered Oct 19 '22 18:10

foolip