Brenna O'Brien / @brnnbrn
resolution independent
great for icons and logos
XML based
= easy to manipulate with CSS & JS
.icon:hover {
fill: goldenrod;
}
anatomy of an SVG element
=
(V.R.E.A.M.)
<text>
<image>
<linearGradient>
<mask>
<filter>
<animate>
<switch> (lolwut)
<tspan>
, works like <span>
fine grained positioning with x
, y
, dx
& dy
class any SVG element for custom CSS
<svg viewBox="0 0 300 200">
<text>
<tspan x="0" dy="1em" font-size="53">what is</tspan>
<tspan class="love" x="0" dy="0.8em" font-size="84">love</tspan>
<tspan x="0" dy="1em" font-size="28">oh baby don't</tspan>
<tspan x="0" dy="0.9em" font-size="48">hurt me</tspan>
</text>
</svg>
text { fill: #fff;}
.love { fill: #FF6666;}
viewBox + flexible container
1. create a path
2. put text on path
<defs>
<path id="arc" d="M82.372,165.969 c44.126-35.084,60.236-50.782,150.325-50.782s131.802,28.198,158.194,62.77" />
</defs>
<text fill="#5D509D" width="500">
<textPath xlink:href="#arc" x="250" font-size="44" dy="100">
Are You Afraid
</textPath>
<!-- ...some more tspans... -->
</text>
where you define re-usable SVG components
a trusty steed as we combine SVG techniques
<linearGradient
x1="0" x2="100%" y1="0" y2="100%" >
<stop stop-color="hotpink" offset="0%"/>
<stop stop-color="goldenrod" offset="100%"/>
</linearGradient>
1. make it a fill with <defs>
<defs>
<lnearGradient id="fire">
<!-- ...gradient stops -->
</lnearGradient>
</defs>
<rect fill="url(#fire)" x="0" y="0" width="100" height="100"/>
2. fill unconventional shapes!
turns any SVG element into a fill
most fun with <image>
turns any SVG element into a fill
most fun with <image>
most fun with gifs
<defs>
<pattern id="bowie" width="100" height="100"
patternUnits="userSpaceOnUse">
<image xlink:href="img/bowie.jpg" width="100" height="100"
preserveAspectRatio="xMidYMid slice">
</pattern>
</defs>
<path fill="url(#bowie)"
d="M98.2,17.305c-2.493-6.252-7.495-11.51-14.416-14.766C77.667-0.34,71.076-0.686,65.085,1.073 C59.096,2.832,53.71,7.626,50,13.168C46.291,7.626,40.905,2.832,34.916,1.073S22.334-0.34,16.217,2.539 C9.297,5.794,4.295,11.053,1.801,17.305c-2.493,6.252-2.504,13.511,0.638,20.73C9.161,53.477,49.787,89.719,50,90.338 c0.213-0.619,40.84-36.861,47.561-52.303C100.705,30.815,100.693,23.557,98.2,17.305z"
/>
V.R.E.A.M.
match <pattern> and <image>
width and height to viewBox
patternUnits="userSpaceOnUse"
<image> needs a width and height
preserveAspectRatio
editorialized text + gradient fills
sorrynotsorry,
-webkit-background-clip: text;
* actually sorry, < IE9
<image>
+
<radialGradient>
+
<mask>
like a cookie cutter
black fill = opaque mask
white fill = transparent mask
see also <clipPath>
<defs>
<radialGradient id="gradient">
<stop offset="80%" stop-color="#fff"/>
<stop offset="100%" stop-color="#000"/>
</radialGradient>
<mask id="vignette" maskUnits="objectBoundingBox">
<ellipse fill="url(#gradient)" cx="365" cy="140" rx="90" ry="120" >
</ellipse>
</mask>
</defs>
<image mask="url(#vignette)" xlink:href="nero-head.jpg" width="200" height="240" preserveAspectRatio="xMidYMin slice" x="270" y="20"/>
<filter id="blur">
<feGaussianBlur stdDeviation="3" />
<feComponentTransfer>
<feFuncR type="linear" slope="0.7"/>
<feFuncG type="linear" slope="0.7"/>
<feFuncB type="linear" slope="0.7"/>
</feComponentTransfer>
</filter>
section:before {
filter: url(#blur);
}
http://www.creativebloq.com/netmag/how-go-beyond-basics-svg-filters-71412280
feTurbulence
noise
feGaussianBlur
feComponentTransfer
RGB channel adjustments
feDiffuseLighting
light source shadows
long
stroke-dasharray
+
animated
stroke-dashoffset
<svg viewBox="0 0 100 10">
<line x2="100" stroke-dasharray="100 100"
stroke-dashoffset="0" stroke="hotpink">
<animate
attributeName="stroke-dashoffset"
dur="2"
values="0; 100"
repeatCount="indefinite"
/>
</line>
</svg>
most SVG attributes are <animate>-able
Animatable SVG attributes<animate> a path's d
attribute
<path fill="goldenrod">
<animate attributeName="d"
dur="2"
repeatCount="indefinite"
values="
M100,0 L200,100 L100,200 L0,100;
M100,50 L125,100 L100,150 L75,100;
M100,0 L200,100 L100,200 L0,100"
/>
</path>
@brnnbrn / thanks!