Editor's note (2026): We've cleaned up this 2014 tutorial. The original code used curly quotes that browsers can't parse; the examples below work as written. We've also added a reduced-motion tip for accessibility.
SVG stands for Scalable Vector Graphics. SVG icons stay sharp at any size, load quickly, and can be styled and animated with CSS, just like HTML. Animated icons can make your website more engaging and help users understand what each icon means.
Cleaning up SVG code
SVG code exported from design tools can be hard to read. Here's what Adobe Illustrator exported for a simple light bulb icon:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="64px" height="64px" viewBox="0 0 64 64"
enable-background="new 0 0 64 64" xml:space="preserve">
<path id="outline" d="M38.178,12.142H25.822v10.723c-1.605,2.67-2.461,6.529-2.461,11.406c0,9.473,4.748,17.587,8.637,17.587s8.641-8.114,8.641-17.587c0-4.881-0.854-8.744-2.461-11.412V12.142z"/>
<rect id="basefill" x="29.822" y="16.142" fill="#4D4B4C" width="4.355" height="4.273"/>
<path id="lightfill" fill="#FFFFFF" d="M31.998,47.768c-1.402-0.959-4.637-6.229-4.637-13.497c0-5.775,1.271-8.566,2.207-9.855h4.857c0.945,1.293,2.213,4.08,2.213,9.855C36.639,41.542,33.402,46.809,31.998,47.768z"/>
</svg>
Tools like Inkscape (free) or SVGOMG (an online optimizer) can simplify this. Here's a cleaned-up version with classes we can target in CSS:
<svg class="svg-light" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path class="outline" d="M38.178,12.142H25.823v10.723c-1.606,2.67-2.461,6.529-2.461,11.406c0,9.473,4.748,17.587,8.636,17.587c3.889,0,8.641-8.114,8.641-17.587c0-4.881-0.854-8.744-2.461-11.412V12.142z"/>
<rect class="base" x="29.822" y="16.142" width="4.355" height="4.273"/>
<path class="bulb" d="M31.998,47.768c-1.402-0.959-4.637-6.229-4.637-13.497c0-5.775,1.272-8.566,2.207-9.856h4.858c0.945,1.293,2.213,4.081,2.213,9.856C36.639,41.542,33.402,46.809,31.998,47.768z"/>
</svg>
Animating the bulb
Use CSS to make the bulb glow:
.svg-light .bulb {
fill: hsl(204, 70%, 23%);
animation: glow-blue 1s ease-in-out infinite alternate;
}
@keyframes glow-blue {
from { fill: hsl(204, 80%, 23%); }
to { fill: hsl(204, 80%, 63%); }
}
/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
.svg-light .bulb {
animation: none;
}
}
The bulb now pulses between dark and light blue.
Basic SVG elements
SVG builds images from simple shapes:
<path>for custom shapes<rect>for rectangles<circle>and<ellipse><line>,<polyline>, and<polygon>
You only need to provide coordinates and sizes. Give each part a class, and you can animate fills, strokes, transforms, and opacity separately. Inline SVG (placed directly in your HTML) is the easiest to style with CSS.
Want your website's icons and graphics to stand out? I.T. For Less can help — contact us.