Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using SVG

Using SVG

Basics of using SVG on the web.

tl;dr I don't think SVG is a pleasure to use yet, but we should be ready when it starts to be.

Matija Marohnić

March 13, 2015
Tweet

More Decks by Matija Marohnić

Other Decks in Technology

Transcript

  1. Why SVG? • can be manipulated with CSS and JS

    • single image, infinite variations • works on @1x, @2x, @100x…
  2. Icons Font • easily edited and generated with IcoMoon •

    fallback glyphs • can be inserted with CSS (with pseudo-elements) • works everywhere (down to IE6)
  3. Icons SVG • one file to rule them all (sprite)

    • multiple colors per icon • editing SVG properties • fewer positioning issues • less repetitive/cheaper updating
  4. Exporting Adobe Illustrator • Profile: SVG 1.1 • Fonts: •

    Type: SVG • Subsetting: None (Use System Fonts) / Only Glyphs Used • Image Location: Link • CSS Properties: Style Elements • Decimal Places: 1 • Output Fewer <tspan> Elements: (selected) • Use <textPath> Element For Text On Path: (selected)
  5. Exporting Sketch • pretty bad results • my suggestion 1.

    copy-paste to Illustrator 2. clean up 3. export
  6. viewBox • tl;dr always include a proper viewBox* • it

    specifies the crop area • remove preserveAspectRatio* * unless you know what you’re doing
  7. Styling Precedence • from the most specific • style attribute

    • <style> tag • presentation attributes
  8. Styling Scope • <img>, background-image, <object> — instances cannot be

    styled • <use> — instance elements hidden behind the Shadow DOM, styling with inheritance • <svg> — full styling capabilities
  9. Animation • CSS animations work on SVG, but not for

    every property • SMIL (Synchronized Multimedia Integration Language) • SMIL works even for <img> and background- image • doesn’t work in IE and Opera Mini
  10. Workflow • An Overview of SVG Sprite Creation Techniques, Sara

    Soueidan • grunt-svgstore • grunticon • SVG fragment identifiers and views
  11. #protip • turn off git diffs for SVG files •

    add this to your .gitattributes:
 
 *.svg -diff
  12. Sources • Using SVG, Chris Coyier • Exporting SVG for

    the web with Adobe Illustrator CC, Michaël Chaize • SVG `symbol` a Good Choice for Icons, Chris Coyier • Structuring, Grouping, and Referencing in SVG — The <g>, <use>, <defs> and <symbol> Elements, Sara Soueidan • An Overview of SVG Sprite Creation Techniques, Sara Soueidan • Tips for Creating Accessible SVG, Léonie Watson • A Guide to SVG Animations (SMIL), Sara Soueidan
  13. Sources • 5 Gotchas You’re Gonna Face Getting Inline SVG

    Into Production, Rob Levin • Namespaces Crash Course, Mozilla Developer Network • Understanding SVG Coordinate Systems and Transformations, Sara Soueidan • Part 1 — The viewport, viewBox, and preserveAspectRatio • Part 2 —The transform Attribute • Part 3 — Establishing New Viewports