Stays sharp
A logo looks clear on a phone and on a large screen. You do not need a separate image for each size.

SVG (Scalable Vector Graphics) is an XML-based format for 2D vector graphics on the web. Shapes are defined with math, so they stay sharp at any size—unlike pixel-based PNG or JPEG images.
A logo looks clear on a phone and on a large screen. You do not need a separate image for each size.
An SVG file is markup you can read, copy, and edit, the same way you edit HTML.
Set fill and stroke on a shape, or change those colors with CSS.
Format: XML markup (text you can read and edit)
Scales: stays sharp when resized
Embed: inline <svg> · <img src="file.svg"> · CSS background
Style: fill, stroke, and CSS classes
Coords: viewBox sets the drawing space Because SVG lives in the DOM when inlined, you can style shapes with CSS and attach events with JavaScript—something you cannot do as easily with a plain PNG.
Three ways to put it on a page. Paste an inline <svg>, use <img src="file.svg">, or set the file as a CSS background. Inline SVG is the one CSS and JavaScript can restyle shape by shape.
Icons, logos, and diagrams need to look crisp on phones and large screens. SVG solves that without shipping many raster sizes.
Vector paths redraw cleanly when the graphic is scaled.
Icons and logos are often tiny as text markup.
Change fill and stroke with CSS. currentColor lets the icon follow the surrounding text color.
Inline shapes can have titles, labels, and focusable links.
Think of an SVG as a coordinate canvas described with tags, not pixels.
<svg>width and height set the size on the page. viewBox sets the drawing coordinates inside it.circle, rect, and path.fill colors the inside of a shape. stroke draws the outline.viewBox="0 0 100 100" means a 100 by 100 drawing that can scale to any display size.Paste this inline in an HTML page. The circle is centered at (50, 50) with radius 40.
<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg> The <svg> element sets the visible size and the viewBox coordinate space.
<circle> draws using a center (cx, cy) and a radius (r).
fill colors the interior. stroke draws the outline.
Next, practice boxes with SVG Rectangle.
Choose the format that matches the job.
| Topic | Canvas | SVG | PNG / JPEG |
|---|---|---|---|
| What it is | Raster pixels drawn with JavaScript | Vector markup | Raster image files |
| Page structure | No element per shape | Each shape is in the DOM | One bitmap |
| Scaling | Can blur if stretched | Stays sharp | Pixelates when enlarged |
| Best for | Games and animation | Icons and diagrams | Photographs |
You need crisp icons, logos, or diagrams. You also want CSS theming, click handlers, and a small file for flat art.
Use Canvas when you redraw many objects every frame, or when you need pixel filters and game sprites. Use PNG or JPEG for photographs and complex pixel art.
See also the Canvas introduction for the bitmap drawing API.
These are the shapes you will meet first in this tutorial.
These are the places SVG shows up on real sites.
They stay sharp on retina screens, and you can recolor them with CSS.
One file scales from a favicon to a large header.
The shapes stay editable as markup.
Flat art is often smaller than a set of PNG sizes.
Each region can be its own element, so a visitor can click it.
Vectors stay clean at high resolution.
<svg>, shapes, fill, and stroke.viewBox plus CSS width and height.Embed inline with <svg> in HTML or link an .svg file via <img>. Use viewBox for responsive scaling. Style shapes with fill, stroke, and CSS.
Browse rectangles, circles, paths, and text, then open each guide.
11 people found this page helpful