by Jackie Keiser / @mongoosedoom

If you're like me, you may have recently realized you know almost nothing about SVGs.

Dude, sucking at something is the first step towards being sort of good at something

Let's fix that!

Scalable
Vector
Graphics

SVGs are vector graphics declared using XML.

Why should we
use them?

  • Small file sizes
  • High quality
  • Scalable without loss in quality

Browser Support

Browser Support

Supports SVG Not Supported
IE 9+
Firefox 3+
Chrome 14+
Safari 4+
Opera 9.6+
iOS 3.2+
Android 3+
IE 6, 7, 8
Android 1-2.3
http://caniuse.com/#feat=svg

Illustrator

Things to remember when exporting

  • Object > Artboards > Fit to Selected Art
  • Named Layers = IDs

Things to avoid in Illustrator

  • Blurred drop shadows
  • 3D effects
  • Blend modes
  • Complex paths

Optimizing

In Illustrator

  • Outline text
  • Removing unwanted groups
  • Pathfinder > Unite

Optimize after exporting

  • SVGO - Node.js based command line tool
    (https://github.com/svg/svgo)
  • SVGOMG! - online tool powered by SVGO
    (https://jakearchibald.github.io/svgomg/)
  • SVG GUI - GUI for SVGO
    (https://github.com/svg/svgo-gui)
  • SVG Editor - online tool
    (http://petercollingridge.appspot.com/svg-editor)
  • grunt-svgmin - Grunt task for using SVGO
    (https://github.com/sindresorhus/grunt-svgmin)

Advantage to SVGOMG! and SVG Editor is that you can preview the output

Using SVG

Use as an img

Coffee! Coffee! Coffee!

Coffee! Coffee! Coffee!

Browser Support: http://caniuse.com/#feat=svg-img

Use as a background-image

.coffee {
  background: url(resources/coffee-pot.svg) no-repeat;
  background-size: 100px;
  width: 100px;
  height: 100px;
}

Browser Support: http://caniuse.com/#feat=svg-css

Use Inline






Using SVG as an object

Your browser does not support SVG
Your browser does not support SVG

Browser Support: http://caniuse.com/#feat=svg

Using Data URIs

This is not a coffee pot
This is not a coffee pot
div {
	background: url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJjb2ZmZWUtcG90IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi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Qo8L3N2Zz4=');
}

Drag and drop URI Converter
(http://jpillora.com/base64-encoder/)

Browser Support: http://caniuse.com/#feat=datauri

Defs and Use

Store elements with defs and reuse elements with use

Defs and Use

defs can be defined at the top of the body


  
     . . . 
     . . . 
  

and reused later on with use


Reference defs from an
external file


Reference defs from an
external file


  • Allows caching
  • More organized
  • Less files
  • Does not work in IE11 :-(


Fallbacks
(http://css-tricks.com/svg-use-external-source/)

Using CSS with SVGs

You can use CSS to manipulate your SVGs

Inline

In a style element


Example
(http://codepen.io/MongooseDoom/full/NPbdVG/)

In an external stylesheet

#coffee-pot-external .liquid {
  fill: #ea7373;
}

Using Media Queries with SVGs

Media Queries

A style tag can be added to an svg file with media queries included. These media queries refer to the size of the SVG viewport. With an img tag, (width: 30em) would apply styles to the SVG when the img is 30em wide.

Example
(http://tympanus.net/Tutorials/ResponsiveSVGs/index6.html)

Resources

Questions?

Thanks!