html
/

HTML SVG: Scalable Vector Graphics

Last Sync: Today

On this page

10
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

html

HTML SVG: Scalable Vector Graphics

What is SVG?

SVG (Scalable Vector Graphics) is used to create vector-based graphics in HTML. Unlike images, SVG graphics scale without losing quality.

Basic Syntax

HTMLRead-only
1
<svg width="200" height="200">
  <circle cx="100" cy="100" r="50" fill="blue" />
</svg>

Common SVG Shapes

ShapeExample
Circle<circle cx="50" cy="50" r="40" />
Rectangle<rect width="100" height="50" />
Line<line x1="0" y1="0" x2="100" y2="100" />
Ellipse<ellipse cx="100" cy="50" rx="80" ry="30" />
Polygon<polygon points="50,0 100,100 0,100" />

SVG Attributes

AttributePurpose
cx, cyCenter position
rRadius
width, heightSize
fillFill color
strokeBorder color
stroke-widthBorder thickness

Example: Multiple Shapes

HTMLRead-only
1
<svg width="200" height="200">
  <rect width="100" height="50" fill="red" />
  <circle cx="100" cy="100" r="40" fill="green" />
</svg>

SVG vs Canvas

FeatureSVGCanvas
TypeVector-basedPixel-based
ScalabilityHighLow
InteractivityBuilt-in DOMRequires JS
Use CaseIcons, diagramsGames, animations

Inline vs External SVG

SVG can be used inline in HTML or as an external file.

HTMLRead-only
1
<img src="image.svg" alt="SVG Image">

Best Practices

  • Use SVG for scalable graphics
  • Optimize SVG files for performance
  • Use inline SVG for styling and animation
  • Keep SVG code clean and minimal
  • Use CSS and JS for interactivity

Common Mistakes

  • Using raster images instead of SVG for icons
  • Overcomplicated SVG paths
  • Not optimizing SVG size
  • Using SVG where canvas is better suited

Conclusion

SVG is ideal for scalable and high-quality graphics. It is widely used for icons, charts, and responsive designs.

Try it yourself

<svg width="150" height="150">
  <circle cx="75" cy="75" r="50" fill="blue" />
</svg>

Test Your Knowledge

Q1
of 3

What does SVG stand for?

A
Scalable Vector Graphics
B
Simple Vector Graphics
C
Smart Visual Graphics
D
Standard Vector Graphics
Q2
of 3

Which is vector-based?

A
Canvas
B
SVG
C
JPEG
D
PNG
Q3
of 3

Which attribute sets fill color?

A
color
B
fill
C
bg
D
style

Frequently Asked Questions

What is SVG?

It is a vector-based graphic format used in HTML.

Is SVG better than images?

For scalable graphics, yes. It does not lose quality when resized.

Can SVG be styled with CSS?

Yes, SVG elements can be styled using CSS.

Previous

html canvas

Next

html web storage

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.