Fireship · @fireship

SVG Explained in 100 Seconds

Uploaded March 24, 2021 · Length 2:20

SVG Explained in 100 Seconds

Summary

svg explained in 100 seconds, scalable vector graphics basics, html for 2d graphics

  • svg
  • scalable vector graphics
  • vector graphics
  • html for graphics
  • 2d graphics

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    scalable vector graphics or svg is an

  2. 0:03

    image format that's like html for

  3. 0:05

    2d graphics they differ from raster

  4. 0:07

    images like png or jpeg

  5. 0:09

    that use a grid of tiny pixels to create

  6. 0:11

    an image and as you zoom in the pixels

  7. 0:13

    become larger making the image grainy in

  8. 0:15

    contrast a vector image can be scaled to

  9. 0:18

    any size without losing its resolution

  10. 0:20

    because instead of fixed pixels its

  11. 0:22

    appearance is based on geometry

  12. 0:24

    you can create svgs with tools like

  13. 0:25

    figma or illustrator

  14. 0:27

    or by writing the code directly which is

  15. 0:29

    easier than you might think

  16. 0:30

    and opens the door to animation and

  17. 0:32

    interactivity create one by opening an

  18. 0:34

    svg tag

  19. 0:35

    then define a coordinate system with the

  20. 0:37

    view box attribute

  21. 0:38

    that gives us a frame with a width and

  22. 0:40

    height of 100 units on which we can draw

  23. 0:42

    graphics draw basic

  24. 0:44

    shapes by adding elements like rectangle

  25. 0:46

    circle and polygon position the

  26. 0:47

    rectangle by defining its x-y value

  27. 0:50

    on the view box then give it a size

  28. 0:52

    which can take values that are either

  29. 0:54

    explicit or responsive

  30. 0:55

    we can change the color of the shape by

  31. 0:57

    defining its fill or define an outline

  32. 0:59

    with the stroke attribute and if our

  33. 1:01

    styling gets too complex we can extract

  34. 1:03

    everything into a separate css

  35. 1:04

    stylesheet

  36. 1:05

    by applying a class to it just like any

  37. 1:07

    html element

  38. 1:08

    we have the full power of css at our

  39. 1:10

    fingertips which means we can react to

  40. 1:12

    events on the shapes and then change

  41. 1:14

    their styling or animation accordingly

  42. 1:16

    but most graphics are more than just

  43. 1:18

    basic shapes they contain complex

  44. 1:20

    artwork with all kinds of twists and

  45. 1:22

    turns and that's where the path element

  46. 1:23

    comes in

  47. 1:24

    the shape of a path is determined by one

  48. 1:26

    attribute d

  49. 1:27

    for draw coding a path is like

  50. 1:29

    controlling the tip of a pen with a

  51. 1:30

    series of commands

  52. 1:32

    the most basic command is m for move

  53. 1:34

    which will move the pen tip to an x y

  54. 1:36

    coordinate

  55. 1:36

    an uppercase letter means move relative

  56. 1:38

    to the view box and lowercase means

  57. 1:40

    move relative to the last point in the

  58. 1:42

    path but move doesn't actually draw

  59. 1:44

    anything

  60. 1:45

    to put the pen tip down on the paper and

  61. 1:47

    draw something use the l command

  62. 1:49

    it works exactly like move but draws a

  63. 1:51

    line that can be styled

  64. 1:52

    straight lines are cool but what if we

  65. 1:54

    wanted to add a curve like we would with

  66. 1:56

    the handles in illustrator

  67. 1:57

    create bezier curves with the c and q

  68. 1:59

    commands define the position of two