Fronteers - 26 June 2022
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<circle cx="30" cy="30" r="10" fill="lightblue" />
<circle cx="70" cy="30" r="10" fill="lightblue" />
<polyline stroke="coral" stroke-width="4" fill="none" points="20,60 40,80 60,80 80,60 "/>
</svg>
<svg aria-labelledby="titleID descID" role="img" viewBox="0 0 720 800">
<title id="titleID">Topographic map of Belgium</title>
<desc id="descID">A map of Belgium showing relief and contour lines.</desc>
...
</svg>
<img>
<img src="banana.svg" width="500" height="500" />
CSS background
.el{
background-image: url(path/to/banana.svg);
}
Inline
<body>
<svg viewBox="0 0 20 20">
<rect x="0" y="0" width="10" height="10" />
</svg>
</body>
document.querySelector('.dot').addEventListener('click', () => {
alert('Congratulations, you clicked on a circle!');
});
scripts.js
.dot {
fill: #BADA55;
stroke: #c0ffee;
stroke-width: 4px;
}
styles.css
<svg viewBox="0 0 50 50">
<circle cx="25" cy="25" r="15" />
</svg>
index.html
<svg viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg">
<circle cx="25" cy="25" r="15" />
</svg>
<svg viewBox="0 0 50 50">
<circle cx="25" cy="25" r="15" class="dot" />
</svg>
ul {
list-style-image: url("data:image/svg+xml, %3Csvg%20xmlns=%27http...");
}
<ul>
<li>Iron Man</li>
<li>Superman</li>
<li>Hulk</li>
</ul>
<svg viewBox="-5 -5 10 10" width="10" height="10" xmlns="http://www.w3.org/2000/svg" >
<style>
circle {
animation: bounce 2s infinite ease-in-out alternate;
}
@keyframes bounce {
to {
transform: scale(0);
}
}
</style>
<circle r="5" />
</svg>
Firefox only 😢
<svg viewBox="min-x min-y width height">
document.querySelector('path').getTotalLength();
<svg viewBox="0 0 200 200">
<foreignObject x="20" y="20" width="160" height="160">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed mollis mollis mi ut ultricies. Nullam magna ipsum,
porta vel dui convallis, rutrum imperdiet eros. Aliquam
erat volutpat.
</p>
</foreignObject>
</svg>
Illustrations © Vegetables - Dialog balloon - Clouds