- 2D vector based image format
- Device and resolution independent
- Human readable XML code
<img>
<embed>
<object>
(can reference internal code and can use fallback image)<iframe>
- Inline
<svg>
- SVG Canvas (drawing area)
- viewport (narrow the focus)
- viewBox (control x, y, and zoom level)
- Graphical Elements (circle, ellipse, line, path, polygon, polyline, rect, text, use)
- Container Elements (defs, g, symbol, svg)
- Gradient Elements (linearGradient and radialGradient)
- Animation Elements (animate, animateMotion, animateTransform, set)
Image Sprite
Inline SVG Sprites ...
- Hidden collection of code snippets for multiple images
- A single SVG tag
<symbol>
element for each image, each has a separate viewBox- Not rendered until
<use>
element - Requires a
display: none;
style - Unique IDs
<svg>
with nested<use>
referencing the symbol ID
PROS
- No http requests
- Code lives in a single location
- No redundancy
CONS
- Image code cannot be cached to speed up load time
- Create one image file, placed as close together as possible, noting position/dimensions for use with "viewBox"
- Add tag with path to the file
#svgView(viewBox(x, y, w, h))
Also
- Create
<view>
with viewBox and ID - Embed method of choice with view-ID
PROS
- Image will be cached by the browser
- Don't need to add viewBox over and over
- May use any embedding technique
CONS
- Individual instances cannot be styled, as with inline
- Needs at least one http request
- Might be difficult to update and edit underlying images
- Using data-URIs
- See GrumpIcon for preparation, including fallback
Three Methods
- CSS
- SMIL
- JavaScript
- Not stable across browsers
- Does not work with external SVG
<img>
- No IE Support, at all
- Snap.svg; IE 9+
- Vivus.js, line art strokes
- D3, animated data visualizations
- Remove hidden items (layers)
- Combine shapes/paths if possible
- Remove any masks if at all possible
- Convert text to outlines
- Trim the canvas
- SVG Optimization Tools
- Examine code and remove any remnants
- Basic Support, IE 9+
- SVG Fragment Identifiers, IE 10+, iOS 8.3, Safari 7.1+, Android 40+, Chrome 36+
- Browser Bugs ... inconsistencies, handling responsiveness of in-line SVGs
- Padding Hack
- responsiveicons.co.uk
- tympanus.net/Development/ElasticSVGElements/
- svg-news.com
- css-tricks.com
- smashingmagazine.com/tag/svg
- picsvg.com
- svgcircus.com
- sarasoueidan.com/tools/curculus/
- grumpicon.com
- Sara Soueidan
- Chris Coyier