mc0de
Advanced HTML · Lesson 06 of 13

HTML SVG

Draw beautiful graphics that stay crisp at any size! Learn how SVG uses shapes, paths, colors, and text to create illustrations, icons, and interactive visual designs.

SVGVector Graphics Shapes & PathsHands-On Practice
● ● ●   svg.html
<svg viewBox="0 0 300 120">
  <circle cx="230" cy="40"
    r="25" fill="#4ee4a1" />
  <path d="M0 110 L90 30
    L180 110 Z" fill="#39d5ed"/>
</svg>
01 / Getting Started

What Makes SVG So Special?

Imagine designing an icon that looks just as sharp on a tiny phone screen as it does on a huge monitor. That’s one of SVG’s biggest strengths!

SVG stands for Scalable Vector Graphics. Instead of storing a picture as pixels, SVG describes shapes using coordinates and instructions.

Remember: SVG shapes stay crisp when resized because the browser draws them from their geometric descriptions.
02 / Your First SVG

Meet the <svg> Element

Unlike Canvas, which uses JavaScript to draw pixels, SVG lets you write shapes directly in your HTML.

Your first SVG
<svg viewBox="0 0 300 150"
     width="300" height="150"
     role="img" aria-label="Blue circle">
  <circle cx="150" cy="75"
          r="50" fill="#39d5ed" />
</svg>

The viewBox defines the internal coordinate system: starting X, starting Y, width, and height. The browser can then scale the graphic while preserving those coordinates.

For a circle, cx and cy specify its center, while r specifies its radius.

03 / Basic Shapes

Circles, Rectangles & Lines

SVG provides several built-in shapes, so you can create graphics without complex drawing commands.

Common SVG shapes
<svg viewBox="0 0 400 180">
  <rect x="20" y="30" width="100"
        height="80" fill="#39d5ed" />

  <circle cx="210" cy="70" r="40"
          fill="#4ee4a1" />

  <line x1="280" y1="30"
        x2="370" y2="120"
        stroke="#176b76" stroke-width="6" />
</svg>

Try changing the coordinates. You’ll quickly see how each number affects the final graphic.

04 / Polygons & Paths

Draw More Interesting Shapes

Need a triangle, mountain, or custom shape? SVG offers <polygon> and <path>.

Polygons and paths
<svg viewBox="0 0 400 200">
  <polygon points="30,170 130,30 230,170"
           fill="#39d5ed" />

  <path d="M200 170 L300 50 L390 170 Z"
        fill="#176b76" />
</svg>

Inside a path’s d attribute, M means move to a point, L means draw a line to a point, and Z closes the path.

Try this: Change one of the path coordinates and watch your mountain change shape in the sandbox.
05 / Colors & Gradients

Add Some Personality

SVG supports fills, strokes, opacity, and gradients. That means you can build polished illustrations without an image editor.

A gradient-filled shape
<svg viewBox="0 0 300 150">
  <defs>
    <linearGradient id="sky" x1="0" y1="0"
                    x2="0" y2="1">
      <stop offset="0%" stop-color="#143c64" />
      <stop offset="100%" stop-color="#39d5ed" />
    </linearGradient>
  </defs>

  <rect width="300" height="150"
        fill="url(#sky)" />
</svg>

The <defs> element stores reusable definitions, and url(#sky) references the gradient by ID.

06 / Text & Accessibility

Put Words in Your Artwork

SVG can display text as part of an illustration using the <text> element.

SVG text
<svg viewBox="0 0 400 120"
     role="img" aria-labelledby="art-title">
  <title id="art-title">Welcome graphic</title>
  <rect width="400" height="120"
        fill="#143c64" />
  <text x="200" y="70"
        text-anchor="middle"
        font-size="28"
        fill="#4ee4a1">
    Hello, mC0de!
  </text>
</svg>

For meaningful SVG images, provide an accessible name using a <title> element or an appropriate ARIA label. Decorative SVGs can instead be hidden from assistive technology.

07 / SVG vs. Canvas

Which One Should You Use?

Both SVG and Canvas create graphics, but they work differently.

  • SVG: Great for icons, logos, charts, diagrams, and scalable illustrations.
  • Canvas: Great for pixel-based drawing, games, and frequently redrawn scenes.
  • SVG shapes: Remain individual elements in the document and can be styled or interacted with.
  • Canvas shapes: Become pixels on a drawing surface rather than separate document elements.
Design tip: Choose the technology that fits your project. You don’t have to use the same graphics technique for everything!
🚀 mC0de Challenge

Create an SVG Landscape Illustration

You’ve learned the tools. Now create your own vector landscape using only SVG elements!

Your Mission

  1. Create an SVG with a viewBox of 0 0 500 300.
  2. Add a background using <rect>.
  3. Draw a sun or moon using <circle>.
  4. Create at least two mountains using polygons or paths.
  5. Add a title with <text>.
  6. Give your artwork an accessible name.
Extra challenge: Create a gradient sky, add stars, or experiment with transparency to make your illustration unique.
💻 Interactive HTML Sandbox

Design Your SVG Landscape!

Change shapes, coordinates, colors, and text in the editor. Click Run Code to see your illustration update in the live result.

Live Result
Lesson 06 Recap

What You’ve Learned

You’re Creating Scalable Artwork!

You now know how to create graphics that look sharp at any size, using nothing more than HTML and SVG.

  • How SVG and its coordinate system work.
  • How to draw circles, rectangles, lines, polygons, and paths.
  • How to apply fills, strokes, and gradients.
  • How to add text and accessible descriptions.
  • When to choose SVG instead of Canvas.

Next up: HTML Video — learn how to bring moving pictures into your web pages!

Your Learning Journey

0 / 13 Completed

Keep going! Every completed lesson brings you closer to mastering Advanced HTML.

🎉

Nice Work!

You've learned how to build scalable vector illustrations using SVG shapes, paths, colors, gradients, and text. Another creative coding skill unlocked!