by Ryan Young, Project Lead at Visionary Services
• Twitter: @rcyou
Like HTML, SVG has its own set of tags and attributes.
<svg>
is like <html>
<rect>
<circle>
<ellipse>
<polygon>
<path>
<g>
<svg>
<circle class="c_solo"/>
<g id="c_bunch">
<circle/>
<circle/>
<circle/>
</g>
</svg>
viewbox="..."
is needed for <svg>
in order to crop and extend the SVG canvas.4
point="..."
is needed for <polygon>
to define what our shape looks like.
d="..."
is needed for <path>
to define lines. 5
img
source.
background-image
in CSS.
<use>
element – though this is similar to using SVG inline.
Just like typical JPG, PNG, or GIF images, you can use SVG as an image source. This is good if you just want to show the image, but you can't change colors or do much animation outside of what you can already do with images.
<img src="some-graphic.svg" alt="company logo">
Be advised: you'll encounter a hiccup if you're using it with PHP or on any kind of Apache server.6
6 "Serve SVG as an Image on Apache with .htaccess" - David WalshSame as <img>
, use a SVG image just like your used to for background images. Best for images that are purely decoration and aren't curcial to UI.
background-image: url('some-graphic.svg');
Some say this is the 'Best SVG'7 because you have a lot of options to manipulate it and make the image more meaningful.
7 "Why Inline SVG is Best SVG" - Front End Center 8 Without minimization, this SVG is ~ 560 lines of code<html>
<body>
View on CodePen 8</body>
</html>
Use <use>
and group things with <g>
!
Also, talk to your dev team about includes