Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 5.6 — SVG in HTML
HTML · Example 3 of 3

img versus inline: who can CSS reach?

The CSS turns the inline circle tomato (CSS beats the fill attribute). The image's circle lives in a separate document that your CSS and JavaScript can't see.

SVG describes pictures as shapes instead of pixels, so they stay sharp at any size; written inline in HTML, every shape is an element you can colour with CSS, which makes SVG ideal for icons, logos and simple graphics.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Draw a 100 × 100 SVG of a traffic light: a dark rounded rectangle with red, amber and green circles stacked vertically.

02

Make a "Delete" button with a decorative cross icon that turns red on hover along with the text.

Explain it without notes

01

What is the difference between vector and raster images, and when is SVG the right choice?

02

What does viewBox do, and how does it relate to width and height?

03

Compare <img src="icon.svg"> with inline <svg>.

04

How do you make an SVG icon accessible, both when it's decorative and when it's the only content of a button?

img versus inline: who can CSS reach?

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Circles in this page's DOM: 1
Inline circle fill: rgb(255, 99, 71)