HTML SVG

You’ve got your page humming along with text and maybe a <canvas> doodle or two, but sometimes you need graphics that stay crisp no matter how big or small the screen gets. That’s where HTML SVG swoops in. SVG stands for Scalable Vector Graphics, which sounds fancy, but it’s just a way to draw shapes with code that don’t get blurry when you zoom. I remember the first time I made a little SVG circle. It was like I’d cracked some secret artist code, and it scaled perfectly on my phone. Let’s jump in and play with it!

The <svg> tag is your starting line. Drop it in your HTML:

<svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="blue" />
</svg>

That’s a blue circle, smack in the middle of a 100x100 space. The cx and cy are the center point, r is the radius, and fill picks the color. I tried this and felt like a geometry whiz. Unlike <canvas>, SVG is all in the HTML, no JavaScript needed yet, which I loved for quick wins.

You can stack shapes too. Here’s a little scene:

<svg width="200" height="200">
<rect x="10" y="10" width="180" height="180" fill="yellow" />
<circle cx="100" cy="100" r="50" fill="red" />
</svg>

A yellow square with a red circle on top, like a funky sun. I messed up once by forgetting to close the <svg> tag, and it was chaos. Always close it! SVG scales like a dream, so it’s perfect for logos or icons.

Here’s one I tinkered with:

<svg width="150" height="100">
<rect x="0" y="0" width="150" height="100" fill="green" />
<line x1="0" y1="0" x2="150" y2="100" stroke="black" stroke-width="2" />
</svg>

A green box with a black diagonal line. That stroke bit adds the line’s color and thickness. Next time you’re coding, toss an <svg> in and draw something. It’s like sketching with math, and it stays sharp no matter where it’s viewed!

How-To Guides for HTML

No How-To Guide is available right now.

Keep Learning & Level Up!

Enhance your HTML skills with our in-depth tutorials and interactive quizzes.

Explore HTML Quiz