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

Intro to SVGs

Intro to SVGs

Cara Michele Ryan

May 14, 2019
Tweet

More Decks by Cara Michele Ryan

Other Decks in Technology

Transcript

  1. Intro to SVGs a.k.a. This Presentation Is a Thing That

    Is Happening, I Guess By Cara Michele Ryan
  2. First of all, why the subtitle? I gave my first

    tech talk in 2014 about SVGs…
  3. What are SVGs? Scalable Vector Graphics • Allows for using

    vector images on web pages • All the major browsers at least sorta kinda support them (IE 9+, Firefox, Safari, Opera, Chrome, etc.) • All the major browsers support them
  4. What are vector graphics? Bitmap/Raster Graphics • Composed of pixels

    – a grid of squares • Scaling it up results in lower quality; you can see the pixels • Common file types: jpg, jpeg, png, gif Vector Graphics • Composed of MATH – mathematically determined points, lines, curves, and shapes • You can scale it to any size because the image is made of math • Common file types: svg, ai (Adobe Illustrator) Raster VS Vector
  5. Why use SVGs? • Scalability – You can make them

    whatever size you want without losing quality. • Less HTTP requests – SVGs can be inserted directly into the markup, or you can create SVG sprites (more on that later) • Manipulatable with CSS/Javascript – Want to change the color of your graphic on the fly? You can!
  6. Getting Familiar with SVGs HTML TAG DESCRIPTION <svg> The container

    for the SVG <g> Container for subelements of the SVG (if you were using layers in your drawing program, it will probably put all the shapes in one layer into one g tag) <line> A line between two points <path> A line that can have curves and more than two points <circle> <ellipse> <rect> <polygon> Some basic, self-explanatory shapes
  7. Getting Familiar with SVGs CSS PROPERT Y DESCRIPTION fill The

    color of the SVG node stroke The border color of the SVG node stroke-width The border width of the SVG node
  8. Getting Familiar with SVGs You can open an SVG file

    in your browser and inspect it like you would inspect any HTML Demo Time!
  9. Why Not Icon Fonts? • Accessibility problems • Semantic problems

    • FOUT (flash of unstyled text) problems • Difficult to edit once generated • Limited to one color icons • Icon fonts are so 2014 and you won’t be cool
  10. Ways to Work with SVGs • Icon fonts • In

    an <img> tag • As a background image • Inline • As SVG sprites
  11. SVGs in <img> tags <img src="/images/butterfly.svg" alt="Butterfly> Pros • As

    easy as using any other type of image Cons • Can't manipulate with CSS/JS • Multiple requests for multiple images • Not utilizing any of the advantages of SVGs besides scalability
  12. SVGs as Background Images Pros • As easy as using

    any other type of image .butterfly { background-image: url("images/butterfly.svg"); } Cons • Can't manipulate with CSS/JS • Multiple requests for multiple images • Not utilizing any of the advantages of SVGs besides scalability • Not semantic if it's not actually being used as a background image
  13. SVGs Inline Pros • SVG code can live in harmony

    with HTML • Can manipulate with CSS/JS Cons • Can't cache <html> <head> <!-- blah blah --> </head> <body> <svg> <!-- svg code --> </svg> </body> </html>
  14. SVG Sprites Pros • SVG code can live in harmony

    with HTML • Can manipulate with CSS/JS • Can cache one file Cons • More complex to set up than the other options <svg> <symbol> <!-- one sprite --> </symbol> <symbol> <!-- second sprite --> </symbol> <!-- etc... --> </svg>