SVG Introduction

Beginner
6 min read
Updated: Nov 2026
Vector graphics

What Is SVG?

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.

Stays sharp

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

Plain text

An SVG file is markup you can read, copy, and edit, the same way you edit HTML.

Easy to style

Set fill and stroke on a shape, or change those colors with CSS.

Remember
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.

Why Use SVG?

Icons, logos, and diagrams need to look crisp on phones and large screens. SVG solves that without shipping many raster sizes.

Sharp at any size

Vector paths redraw cleanly when the graphic is scaled.

Small flat graphics

Icons and logos are often tiny as text markup.

Themeable UI

Change fill and stroke with CSS. currentColor lets the icon follow the surrounding text color.

Accessible markup

Inline shapes can have titles, labels, and focusable links.

How an SVG Drawing Works

Think of an SVG as a coordinate canvas described with tags, not pixels.

<svg>
The root container. width and height set the size on the page. viewBox sets the drawing coordinates inside it.
Shapes
Elements that draw the geometry. You will start with circle, rect, and path.
Paint
fill colors the inside of a shape. stroke draws the outline.
viewBox
The internal coordinate system. viewBox="0 0 100 100" means a 100 by 100 drawing that can scale to any display size.

Your First SVG Shape

Paste this inline in an HTML page. The circle is centered at (50, 50) with radius 40.

HTML
<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>
Try It Yourself

How it works

  1. Root

    The <svg> element sets the visible size and the viewBox coordinate space.

  2. Shape

    <circle> draws using a center (cx, cy) and a radius (r).

  3. Paint

    fill colors the interior. stroke draws the outline.

Next, practice boxes with SVG Rectangle.

SVG vs Canvas vs PNG

Choose the format that matches the job.

TopicCanvasSVGPNG / JPEG
What it isRaster pixels drawn with JavaScriptVector markupRaster image files
Page structureNo element per shapeEach shape is in the DOMOne bitmap
ScalingCan blur if stretchedStays sharpPixelates when enlarged
Best forGames and animationIcons and diagramsPhotographs

When to choose which

Choose SVG

You need crisp icons, logos, or diagrams. You also want CSS theming, click handlers, and a small file for flat art.

Choose Canvas or a raster image

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.

Common SVG Elements

These are the shapes you will meet first in this tutorial.

  1. 01 Rectangle <rect> Draw a box with position, width, and height.
  2. 02 Circle <circle> Draw a circle from a center point and a radius.
  3. 03 Ellipse <ellipse> Draw an oval with two radii.
  4. 04 Line <line> Draw a straight line between two points.
  5. 05 Polygon <polygon> Draw a closed shape with several sides.
  6. 06 Path <path> Draw any custom outline, from a curve to a logo.
  7. 07 Text <text> Place words inside the drawing.

Where Is SVG Used?

These are the places SVG shows up on real sites.

UI icons

They stay sharp on retina screens, and you can recolor them with CSS.

Logos and branding

One file scales from a favicon to a large header.

Charts and diagrams

The shapes stay editable as markup.

Illustrations

Flat art is often smaller than a set of PNG sizes.

Interactive maps

Each region can be its own element, so a visitor can click it.

Print-friendly graphics

Vectors stay clean at high resolution.

Keep This in Mind

  • SVG is vector markup that stays sharp at any size.
  • Build with <svg>, shapes, fill, and stroke.
  • Scale with viewBox plus CSS width and height.
  • SVG or Canvas: use SVG for shapes in the page, and Canvas for pixel animation.

Frequently Asked Questions

SVG (Scalable Vector Graphics) is an XML-based format for 2D vector graphics. Shapes are defined mathematically, so they stay sharp at any size—unlike pixel-based PNG or JPEG images.
Often yes for simple icons and logos. SVG scales cleanly and stays small for flat graphics. PNG is better for photographs and complex raster artwork.
Yes. Paste an inline <svg> block, use <img src="icon.svg">, or set SVG as a CSS background. Inline SVG lets CSS and JavaScript target individual shapes.
SVG is DOM-based vector markup—each shape is an element you can style and click. Canvas is a bitmap surface drawn with JavaScript pixels. SVG suits icons and diagrams; Canvas suits games and heavy animation.
All modern browsers support SVG. It is a W3C web standard and safe for current projects.
Practice rectangle, circle, ellipse, line, polygon, polyline, path, and text. Then explore stroke, filters, patterns, gradients, and interactivity.

Did you know?

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.

Next: Basic Shapes

Browse rectangles, circles, paths, and text, then open each guide.

Basic Shapes →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful