An introduction to writing SVG code by hand and integrating it with CSS effects like animations & transitions.
Advanced SVG
We can open them directly in our code editor
They’re completely hackable!
SVGs look very similar to HTML—but they are XML
<svg>
<circle>
<rect>
<ellipse>
<svg width="256" height="256" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"> <circle cx="120" cy="120" r="50" /> <rect x="0" y="0" width="75" height="75" /> <ellipse cx="200" cy="200" rx="50" ry="30" /> </svg>
Most of the visual look of SVGs comes from CSS
Just the properties are a little different
rect { fill: yellow; } ellipse { fill: limegreen; stroke: #000; stroke-width: 5px; }
We can also write the styles directly on the tags—and when we export from Illustrator that’s what happens
The SVG style attributes can be overwritten by CSS
<svg width="256" height="256" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"> <circle fill="limegreen" cx="120" cy="120" r="50" /> </svg>
circle { fill: yellow; }
The SVG code can be embedded directly in your HTML
Just copy and paste all the SVG code
<body> <svg width="256" height="256" viewBox="0 0 256 256"> <circle cx="120" cy="120" r="50" /> </svg> </body>
Embedded SVGs can have effects:
:hover
transition
animation
transform
<svg id="black-hole" width="256" height="256" viewBox="0 0 256 256"> <circle cx="120" cy="120" r="50" /> </svg>
#black-hole { transition: all .5s linear; } #black-hole:hover { fill: lightsteelblue; }