Created by Krystsina Gerko
| Canvas | SVG | |
|---|---|---|
| Image Format | Bitmap | Vector |
| Quality by resizing | Low | High |
| Canvas | SVG | |
|---|---|---|
| Image Format | Bitmap | Vector |
| Quality by resizing | Low | High |
| Knowledge | HTML & JS | HTML & XML |
HTML
<canvas id="canvas" width="500" height="300"></canvas>
JavaScript
let canvas = document.getElementById("canvas");
let ctx = canvas.getContext('2d');
ctx.fillRect(x, y, width, height);
ctx.fillStyle = "#f92672";
ctx.fillRect(100, 50, 100, 100);
ctx.rect(100, 50, 100, 100);
ctx.stroke();
ctx.moveTo(60, 60); // start
ctx.lineTo(200, 100); // end
ctx.stroke();
ctx.beginPath();
ctx.arc(100, 100, 80, 0, 2 * Math.PI);
// x, y, radius, startAngle, endAngle
ctx.stroke();
| Canvas | SVG | |
|---|---|---|
| Knowledge | HTML & JS | HTML & XML |
| Can be modified through | script | script & CSS |
| Interaction | No support for event handlers | Support for event handlers |
| Canvas | SVG | |
|---|---|---|
| Size of file | don't increase too much | increase too much |
| Usage | Difficult pictures, game applications; not recommended for large screens | Icons, logos, static pictures, animation; recommended for large screens |
Google is our best friend :)