CHAPTER 48 · HTML
SVG graphics: describe shapes and a simple diagram
Read coordinates, shapes and a viewBox. Build original graphics that scale while keeping their meaning available in words.
Download example files (ZIP)A drawing described by shapes
Two ways to place SVG on a page
Coordinates: right and down
Rectangles, outlines and fills
ViewBox separates drawing coordinates from display size
Text and reading meaning
Give useful graphics a name and explanation
Keep SVG sources trustworthy
Follow the idea
- 1ViewBox: the drawing rectangle
- 2Coordinates: right and down
- 3Fill and stroke: inside and outline
- 4Text: describe the same meaning
Shapes remain document elements; provide a useful text explanation.
Complete program: svg-shapes.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Describe Simple Vector Shapes</title>
<style>
svg {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<h1>Draw two shapes with SVG</h1>
<main>
<p>The drawing contains a blue circle and a pale rectangle with a dark border.</p>
<svg
width="320"
height="160"
viewBox="0 0 320 160"
role="img"
aria-labelledby="shapes-title"
aria-describedby="shapes-desc"
>
<title id="shapes-title">Two practice shapes</title>
<desc id="shapes-desc">
A blue circle on the left and a pale rectangle on the right. The shapes do not represent
different levels of importance.
</desc>
<circle cx="75" cy="80" r="42" fill="#2458a6"></circle>
<rect
x="155"
y="38"
width="125"
height="84"
fill="#e8f0ff"
stroke="#202c3a"
stroke-width="3"
></rect>
</svg>
</main>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Complete program: svg-steps.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A Two-Step Vector Diagram</title>
<style>
svg {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<h1>Show the direction of a practice task</h1>
<main>
<p>
First save the file, then open it in a browser. The diagram repeats that order visually.
</p>
<svg
width="360"
height="160"
viewBox="0 0 360 160"
role="img"
aria-labelledby="steps-title"
aria-describedby="steps-desc"
>
<title id="steps-title">Save, then open</title>
<desc id="steps-desc">An arrow goes from a box labelled Save to a box labelled Open.</desc>
<rect x="20" y="45" width="120" height="60" rx="8" fill="#e8f0ff" stroke="#2458a6"></rect>
<rect x="220" y="45" width="120" height="60" rx="8" fill="#e8f0ff" stroke="#2458a6"></rect>
<line x1="140" y1="75" x2="216" y2="75" stroke="#202c3a" stroke-width="3"></line>
<polygon points="206,67 218,75 206,83" fill="#202c3a"></polygon>
<text x="80" y="81" text-anchor="middle" font-size="18" fill="#202c3a">Save</text>
<text x="280" y="81" text-anchor="middle" font-size="18" fill="#202c3a">Open</text>
</svg>
</main>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Problem and solution
Common mistakes and useful tips
Do not confuse a centre point with a rectangle corner. Y increases downward in the default system. Use the correct viewBox spelling. Do not rely on colour or arrows as the only explanation. Keep label ids unique. Do not assume an unknown SVG contains only harmless shapes.
Practice questions
What does SVG stand for? Which circle attribute controls radius? Which direction increases y by default? What do the last two viewBox numbers describe? Does SVG text wrap like an ordinary HTML paragraph? Save the shapes program and change cx from 75 to 90, then restore it. What moves?
Check your practice answers
Scalable Vector Graphics. R. Downward. The drawing rectangle's width and height. Not automatically; these labels need to fit their intended area. The circle moves 15 drawing units to the right. Its radius and the rectangle remain unchanged.
Interview questions
How does inline SVG differ from img?
Why use viewBox?
Why keep a visible diagram explanation?
Is every SVG inherently safe or made entirely of vector shapes?
Quick revision
Read coordinates and dimensions separately. Use fill and stroke intentionally. Give the drawing a clear text meaning. Test scaling and keep sources trustworthy.