SVG
In one line
SVG (Scalable Vector Graphics) is an XML-based format for describing two-dimensional graphics that scale without losing quality.
In simple words
SVG is a vector image format — instead of a grid of pixels (like PNG or JPEG), it describes shapes with mathematical paths: lines, curves, rectangles, circles. Because the image is defined by geometry, it scales to any size without pixelation, making SVG perfect for icons, logos, and diagrams.
In the browser, SVG can be written directly in HTML as an <svg> element. Each shape (<rect>, <circle>, <path>) is a real DOM node, so you can style it with CSS and manipulate it with JavaScript. This makes SVG interactive and animatable in ways raster images are not.
Use SVG for crisp icons and illustrations that must look sharp on high-DPI screens, for data visualizations (D3.js builds on SVG), and for graphics that need CSS/JS interaction. Use Canvas or raster images for complex photographs or scenes with many elements, where SVG's DOM overhead hurts performance.
Example
// SVG written inline in HTML — each shape is a DOM element
/* <svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="blue" />
<text x="50" y="55" text-anchor="middle" fill="white">Hi</text>
</svg> */
// Manipulate with JS just like any DOM element
const circle = document.querySelector("circle");
circle.addEventListener("click", () => {
circle.setAttribute("fill", "red");
});The SVG circle is a DOM node. setAttribute changes its fill color on click — SVG shapes are interactive and styleable.
Related terms
Related Resources
Related Lessons
- SVG
Learn vector graphics.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.