Fork of HTML Starter
This example compares the SVG and Canvas rendering models through a static webpage that combines a bulleted informational list with a live SVG drawing. The visualization demonstrates fundamental SVG properties—such as the default 300×150 canvas size, the use of the `fill` attribute, and the inability to set `fill` directly on the `<svg>` tag—by rendering three circles. The code uses raw SVG elements (`<circle>`) to illustrate the effects of explicit fill colors, no fill with a green stroke, and default black fills. The page also presents a detailed comparison table outlining differences in resolution dependence, event handler support, text rendering, and suitability for complex applications versus games.
AI-generated descriptionCanvas 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.
<h2>Comparison of Canvas and SVG</h2> The table below shows some important differences between Canvas and SVG: <br/><br/> <table class="table"> <thead> <tr> <th scope="col">Canvas</th> <th scope="col">SVG</th> </tr> </thead> <tbody> <tr> <td>
<ul>
<li>Resolution dependent</li>
<li>No support for event handlers</li>
<li>Poor text rendering capabilities</li>
<li>You can save the resulting image as .png or .jpg</li>
<li>Well suited for graphic-intensive games</li>
</ul>
</td>
<td>
<ul>
<li>Resolution independent</li>
<li>Support for event handlers</li>
<li>Best suited for applications with large rendering areas (Google Maps)</li>
<li>Slow rendering if complex (anything that uses the DOM a lot will be slow)</li>
<li>Not suited for game applications</li>
</ul>
</td>
</tr>
</tbody>
</table>