D DevBrainBox

HTML5 Svg

HTML

What is SVG?

SVG stands for Scalable Vector Graphics.

It is an XML-based format for drawing vector graphics — such as lines, rectangles, circles, text, and even complex paths — directly in the browser.

Unlike images (PNG, JPG), SVG graphics scale without losing quality, because they’re based on geometry, not pixels.

Why use SVG?

FeatureDescription
ScalableCan resize without loss of quality (no pixelation).
Text-basedWritten in XML, easy to edit or manipulate.
StylableCan use CSS to style shapes.
AnimatableCan animate with SMIL, CSS or JavaScript.
InteractiveCan attach events (click, hover, etc.).
<svg width="200" height="200">
    <circle cx="100" cy="100" r="50" fill="orange" stroke="black" stroke-width="3" />
</svg>

<svg>: defines the SVG container (width 200, height 200).

<circle>: draws a circle.

  • cx & cy: center x and y position (100,100).
  • r: radius (50).
  • fill: fill color (orange).
  • stroke: border color (black).
  • stroke-width: width of the border.

Comparison: SVG vs Canvas

FeatureSVGCanvas
TypeVector-based (XML)Pixel-based (bitmap)
DOM nodesShapes are part of DOMDrawings are pixels on a bitmap
ScalableInfinitely scalableMay pixelate when scaled
InteractivityEasy to add events to elementsRequires manual hit-testing
Best forDiagrams, icons, chartsGames, complex animations

On this page