Basic Shapes
There are only a handful of
Technically not a basic shape.
Basic Shapes are shortcuts to paths.
Slide 7
Slide 7 text
Let’s spend like 15 seconds
looking at SVG syntax.
Even though most of us will hardly ever touch it
directly because there are great tools for it.
Slide 8
Slide 8 text
Slide 9
Slide 9 text
Slide 10
Slide 10 text
Slide 11
Slide 11 text
Slide 12
Slide 12 text
Slide 13
Slide 13 text
Slide 14
Slide 14 text
Slide 15
Slide 15 text
Slide 16
Slide 16 text
“Beaker” by Ben Joyce :: codepen.io/benjoyce/full/myqxad/
Slide 17
Slide 17 text
“Beaker” by Ben Joyce :: codepen.io/benjoyce/full/myqxad/
Slide 18
Slide 18 text
“Gradient Reuse in SVG” by Me :: codepen.io/chriscoyier/pen/ByOWYO/
Slide 19
Slide 19 text
“Gradient Reuse in SVG” by Me :: codepen.io/chriscoyier/pen/ByOWYO/
Slide 20
Slide 20 text
“Gradient Reuse in SVG” by Me :: codepen.io/chriscoyier/pen/ByOWYO/
Slide 21
Slide 21 text
“Gradient Reuse in SVG” by Me :: codepen.io/chriscoyier/pen/ByOWYO/
Slide 22
Slide 22 text
“Gradient Reuse in SVG” by Me :: codepen.io/chriscoyier/pen/ByOWYO/
Slide 23
Slide 23 text
“Nature’s Journey” demo file that comes with Adobe Illustrator
Slide 24
Slide 24 text
“Nature’s Journey” demo file that comes with Adobe Illustrator
LET THERE
BE ART
Slide 25
Slide 25 text
But why would you even
Use SVG?
1 Resolution independent
2 Design possibilities
3 Use as a system
Slide 26
Slide 26 text
SCREEN SIZE & RESOLUTIONS
Cliché conference presentation graphic depicting different
Slide 27
Slide 27 text
1999
SVG was born in
Slide 28
Slide 28 text
No content
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
Why send pixel data when you can send
geometry?
Math is more efficient!
Let your powerful computer* do the drawing.
*The connection between this idea and client-side MVC is interesting.
shoptalkshow.com/episodes/147-tom-dale/
Slide 31
Slide 31 text
1999
SVG was conceived in
Slide 32
Slide 32 text
2015
SVG was conceived in
Slide 33
Slide 33 text
“Nature’s Journey” demo file that comes with Adobe Illustrator
Slide 34
Slide 34 text
That one would be a little
impractical on the web.
Because it’s like 30 MB.
One of the advantages of SVG is that for simple graphics, the file
size is smaller and the quality is higher (best of both worlds).
But there is a complexity limit.
Slide 35
Slide 35 text
No content
Slide 36
Slide 36 text
DEFINITELY!
Slide 37
Slide 37 text
No content
Slide 38
Slide 38 text
PRROBBBBLY.
(test the zipped file size)
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
NOPE!
Slide 41
Slide 41 text
No content
Slide 42
Slide 42 text
Mayyyyybe.
test context, gzipped size, display size, etc.
Slide 43
Slide 43 text
“SVG Animation” by Jose Aguinaga :: codepen.io/jjperezaguinaga/full/yuBdq/
Slide 44
Slide 44 text
“Super Nintendo Controller SNES” by Amar Chauhan :: codepen.io/beedesigned/pen/WbZzQx/
Slide 45
Slide 45 text
No content
Slide 46
Slide 46 text
No content
Slide 47
Slide 47 text
No content
Slide 48
Slide 48 text
No content
Slide 49
Slide 49 text
No content
Slide 50
Slide 50 text
No content
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
No content
Slide 53
Slide 53 text
No content
Slide 54
Slide 54 text
No content
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
No content
Slide 57
Slide 57 text
No content
Slide 58
Slide 58 text
No content
Slide 59
Slide 59 text
No content
Slide 60
Slide 60 text
No content
Slide 61
Slide 61 text
No content
Slide 62
Slide 62 text
No content
Slide 63
Slide 63 text
Pretty useful for
and/or
Slide 64
Slide 64 text
Slide 65
Slide 65 text
inkscape.org
Slide 66
Slide 66 text
If you can get your hands
on the vector art…
you can easily get that into SVG for use on the web.
Slide 67
Slide 67 text
No content
Slide 68
Slide 68 text
No content
Slide 69
Slide 69 text
No content
Slide 70
Slide 70 text
There are three* useful ways to
USE SVG ON THE WEB
1 SVG as in HTML
2 SVG as background-image in CSS
3 Inline SVG in HTML
* There are more ways, like , , and - but I don’t think they are very useful so let’s ignore them.
SVG is pretty efficient already,
but it can also be heavily optimized
in multiple ways.
cool fact
Slide 83
Slide 83 text
SVG gzips very well, because it has a lot of
repetitive strings. Be sure to enable that
on your server for .svg and when testing
to decide to use or not, test different
formats against the gzipped sizes.
Slide 84
Slide 84 text
SVG gzips very well, because it has a lot of
repetitive strings. Be sure to enable that
on your server for .svg and when testing
to decide to use or not, test different
formats against the gzipped sizes.
AddType image/svg+xml .svg .svgz
AddOutputFilterByType DEFLATE text/html image/svg+xml
HTaccess
PNG
16 K
SVG
319 K CRAZY EXPERIMENT
24 K CRAZY EXPERIMENT, GZIPPED
Slide 97
Slide 97 text
PNG
16 K
SVG
319 K CRAZY EXPERIMENT
24 K CRAZY EXPERIMENT, GZIPPED
? K SHOULDA BEEN AN SVG AM I RIGHT?
Slide 98
Slide 98 text
SVGO is great for optimizing .svg files.
This demo is SVGO-GUI :: github.com/svg/svgo-gui
The core library / command-line tools is here :: github.com/svg/svgo
A visual in-browser version by Jake Archibald is here :: jakearchibald.github.io/svgomg/
Slide 99
Slide 99 text
SVGO is great for optimizing .svg files.
This demo is SVGO-GUI :: github.com/svg/svgo-gui
The core library / command-line tools is here :: github.com/svg/svgo
A visual in-browser version by Jake Archibald is here :: jakearchibald.github.io/svgomg/
Slide 100
Slide 100 text
SVG makes for an excellent
ICON SYSTEM
Icons are incredibly common on the web.
Tons of sites make use of them because they are
useful visual indicators. The style of them
change over time, but the concept isn’t a trend.
Slide 101
Slide 101 text
No content
Slide 102
Slide 102 text
No content
Slide 103
Slide 103 text
No content
Slide 104
Slide 104 text
No content
Slide 105
Slide 105 text
No content
Slide 106
Slide 106 text
The classic problem:
Say a site needs 20 icons. You really don’t
want to make 20 separate HTTP requests
for those. That would be slow. One of the
top ways to make sites faster is to make less
requests.
An icon system does two things:
1. All icons are in one request.
2. It makes icons easy to use.
Slide 107
Slide 107 text
Past solution to this same problem: CSS Sprites
Slide 108
Slide 108 text
Past solution to this same problem: Icon Fonts
Slide 109
Slide 109 text
Quick Aside
It’s looking like HTTP/2 will make
concatenating assets an anti-pattern.
Because. Uh. Reasons.
I think there is no penalty for requesting multiple assets from
the same host and no extra cookie overhead. So if you leave
all the icons separate, you can change a single icon without
breaking the cache on all of them.
Slide 110
Slide 110 text
Let’s do this thing.
How to make an icon system from inline SVG
Slide 111
Slide 111 text
Slide 112
Slide 112 text
Slide 113
Slide 113 text
Slide 114
Slide 114 text
Slide 115
Slide 115 text
Slide 116
Slide 116 text
Follow us on Twitter
Slide 117
Slide 117 text
Follow us on Twitter
Slide 118
Slide 118 text
Follow us on Twitter
Slide 119
Slide 119 text
To use…
Put this anywhere in the HTML.
Slide 120
Slide 120 text
No content
Slide 121
Slide 121 text
No content
Slide 122
Slide 122 text
“Step 7: styling an icon group” by Benedikte Vanderweeën :: codepen.io/Benedikte/pen/rAjad
Slide 123
Slide 123 text
“Step 7: styling an icon group” by Benedikte Vanderweeën :: codepen.io/Benedikte/pen/rAjad
Slide 124
Slide 124 text
No content
Slide 125
Slide 125 text
Slide 126
Slide 126 text
Leveling up up our icon system
1. Let’s make a build tool do the hard part
2. Let’s ajax for the SVG defs, so we can browser cache
3. Let’s add a fallback for non-supporting browsers
Slide 127
Slide 127 text
CodePen Logo
Three dimensional box
surrounded by a circle.
CodePen Logo
Three dimensional box
surrounded by a circle.
CodePen Logo
Three dimensional box
surrounded by a circle.
Slide 128
Slide 128 text
defs.svg
CodePen Logo
Three dimensional box
surrounded by a circle.
CodePen Logo
Three dimensional box
surrounded by a circle.
CodePen Logo
Three dimensional box
surrounded by a circle.
Slide 129
Slide 129 text
Let’s make a computer
build the sprite for us.
We could do it ourselves, but that’s more
work and error-prone.
Slide 130
Slide 130 text
IcoMoon is
very awesome.
Slide 131
Slide 131 text
IcoMoon
gave us this
Using the icons
is as easy
as this.
Slide 132
Slide 132 text
No content
Slide 133
Slide 133 text
Command line build
systems are even more
awesome.
Slide 134
Slide 134 text
How about a little
graceful degradation
and browser caching?
Slide 135
Slide 135 text
First, test to see if
inline SVG is supported.
var supportsSvg = function() {
var div = document.createElement('div');
div.innerHTML = '';
return (div.firstChild &&
div.firstChild.namespaceURI) ==
'http://www.w3.org/2000/svg';
};
Slide 136
Slide 136 text
if (supportsSvg()) {
// Ajax for the defs.svg
} else {
// We’re going to need a fallback
}
Slide 137
Slide 137 text
var ajax = new XMLHttpRequest();
ajax.open("GET", "defs.svg", true);
ajax.responseType = "document";
ajax.onload = function(e) {
document.body.insertBefore(
ajax.responseXML.documentElement,
document.body.childNodes[0]
);
}
ajax.send();
Ajax means we can browser
cache the response.
Slide 138
Slide 138 text
For the fallback, one option is to
use Grunticon.
Grunticon is a whole system onto itself, so
you can definitely just use it exactly as is. But
Grunticon doesn’t start with inline SVG in the
HTML like we are doing here.
We can still use it and do things our own way.
Details!
css-tricks.com/inline-svg-grunticon-fallback/
Slide 139
Slide 139 text
Class name that Grun.con
automa.cally creates from the file
name.
Slide 140
Slide 140 text
if (supportsSvg()) {
// Ajax stuff here.
} else {
grunticon([
"",
"/fallbacks/icons.data.png.css",
"/fallbacks/icons.fallback.css"
]);
}
Don’t load anything
in a “supported” scenario
Slide 141
Slide 141 text
No content
Slide 142
Slide 142 text
No content
Slide 143
Slide 143 text
Should the day come that you don’t need
a fallback anymore, just stop running
Grunticon and doing the support test.
Slide 144
Slide 144 text
OK, SHEESH.
Why do it this way? What are the advantages?
Slide 145
Slide 145 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
css-tricks.com/icon-fonts-vs-svg/
Slide 146
Slide 146 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
2. Easy mulE-color!
More CSS control than any other method.
css-tricks.com/icon-fonts-vs-svg/
Slide 147
Slide 147 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
2. Easy mulE-color!
More CSS control than any other method.
3. Animate!
Easy to apply transitions and animations.
css-tricks.com/icon-fonts-vs-svg/
Slide 148
Slide 148 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
2. Easy mulE-color!
More CSS control than any other method.
3. Animate!
Easy to apply transitions and animations.
4. Script away!
Everything is in the DOM.
css-tricks.com/icon-fonts-vs-svg/
Slide 149
Slide 149 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
2. Easy mulE-color!
More CSS control than any other method.
3. Animate!
Easy to apply transitions and animations.
4. Script away!
Everything is in the DOM.
5. BeKer accessibility! Plus fallbacks!
Fool-proof, once you set it up well.
css-tricks.com/icon-fonts-vs-svg/
Slide 150
Slide 150 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
2. Easy mulE-color!
More CSS control than any other method.
3. Animate!
Easy to apply transitions and animations.
4. Script away!
Everything is in the DOM.
5. BeKer accessibility! Plus fallbacks!
Fool-proof, once you set it up well.
6. BeKer semanEcs!
= “image” / = “nothing”
css-tricks.com/icon-fonts-vs-svg/
Slide 151
Slide 151 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
2. Easy mulE-color!
More CSS control than any other method.
3. Animate!
Easy to apply transitions and animations.
4. Script away!
Everything is in the DOM.
5. BeKer accessibility! Plus fallbacks!
Fool-proof, once you set it up well.
6. BeKer semanEcs!
= “image” / = “nothing”
7. Ease of use
Easy to manage individual icons, instant build processes.
css-tricks.com/icon-fonts-vs-svg/
Slide 152
Slide 152 text
1. Vector!
Typically sharper than icon fonts because of non-text anti-aliasing.
2. Easy mulE-color!
More CSS control than any other method.
3. Animate!
Easy to apply transitions and animations.
4. Script away!
Everything is in the DOM.
5. BeKer accessibility! Plus fallbacks!
Fool-proof, once you set it up well.
6. BeKer semanEcs!
= “image” / = “nothing”
7. Ease of use
Easy to manage individual icons, instant build processes.
css-tricks.com/icon-fonts-vs-svg/
Slide 153
Slide 153 text
No content
Slide 154
Slide 154 text
No content
Slide 155
Slide 155 text
No content
Slide 156
Slide 156 text
Speaking of icons, The Noun Project
is the best site ever for finding simple
vectors for about anything.
Slide 157
Slide 157 text
No content
Slide 158
Slide 158 text
No content
Slide 159
Slide 159 text
SVG is pretty great at
ANIMATION
1 Animate with CSS
2 Animate with SMIL
3 Animate with JavaScript
Slide 160
Slide 160 text
Animating SVG with CSS is just like
animating HTML with CSS.
If it’s inline SVG, the CSS can be anywhere,
like with the rest of the CSS for your page.
If you use the SVG any other way, you have
to embed the CSS within the SVG.
CSS
Slide 161
Slide 161 text
No content
Slide 162
Slide 162 text
No content
Slide 163
Slide 163 text
Animating SVG with JavaScript
can mean many different things.
JavaScript can do anything!
JS
Slide 164
Slide 164 text
var circle = document.getElementById("orange-circle"),
positionX = 0;
setInterval(function() {
positionX += 10;
circle.setAttribute("cx", positionX);
if (positionX > 500) {
positionX = 0;
}
}, 20);
This is just a dumb ol’ loop that changes
an attribute. But that’s animation!
Slide 165
Slide 165 text
Typically, it means use a library. All of these work
with SVG, but all have slightly different capabilities,
approaches, and focuses.
1. Greensock (GSAP)
greensock.com - does some cool normalization stuff too
2. Snap.svg
snapsvg.io - jQuery for SVG - kinda like newer Raphaël
3. Velocity.js
julian.com/research/velocity
4. SVG.js
svgjs.com
5. D3
d3js.org - data powerhouse
Slide 166
Slide 166 text
“High Five SVG Animation” by MailChimp UX :: codepen.io/mailchimpux/pen/Gblcs
Slide 167
Slide 167 text
“Yes/No SVG Tick Animation” by Chris Gannon :: codepen.io/chrisgannon/pen/ogEjRa/
Slide 168
Slide 168 text
codepen.io/sdras/pen/dPqRmP
Slide 169
Slide 169 text
No content
Slide 170
Slide 170 text
No content
Slide 171
Slide 171 text
No content
Slide 172
Slide 172 text
No content
Slide 173
Slide 173 text
No content
Slide 174
Slide 174 text
No content
Slide 175
Slide 175 text
You can do
CLIPPING
& MASKING
Clipping paths are always vector. Inside the vector
shape is shown, outside the vector path is hidden.
Masks are images. They can be vector too, but they
don’t have to be.
Slide 176
Slide 176 text
“SVG Mask (Experiment)” by Noel Delgado :: codepen.io/noeldelgado/pen/ByxQjL
Slide 177
Slide 177 text
No content
Slide 178
Slide 178 text
It’s overused already but who cares it’s awesome
LINE DRAWING
Slide 179
Slide 179 text
No content
Slide 180
Slide 180 text
“Animated SVG Headphones” by Chris Gannon :: codepen.io/chrisgannon/pen/zxWowX
Slide 181
Slide 181 text
SVG is pretty great at
CHARTING
Lines? Shapes? Math? Heck yeah.
SVG doesn’t have charting-specific features. It has
features that lend themselves well to charting.
Slide 182
Slide 182 text
“Draw SVG Graph” by Chris Gannon :: codepen.io/chrisgannon/pen/PwQXgG
Slide 183
Slide 183 text
amCharts.com
amCharts.com
Slide 184
Slide 184 text
No content
Slide 185
Slide 185 text
The original gangsters
SVG FILTERS
“The Gooey Effect” by Lucas Bebber :: css-tricks.com/gooey-effect/
Slide 186
Slide 186 text
More, more,
MORE
All this has been the tip of the
iceberg. There is a TON to
know about SVG that we
didn’t cover. I mostly wanted
to just get you more excited
about it.
Huge list of information about SVG:
css-tricks.com/mega-list-svg-information/