This lesson is exclusive to members

Responsive Web Design Essentials - HTML5 CSS3 Bootstrap

When would you use an svg image instead of jpg or png in web design

Daniel Walter Scott

Download Exercise Files Download Completed Files

Contents

Certificates

We’re awarding certificates for this course!

Check out the How to earn your certificate video for instructions on how to earn yours and click the available certificate levels below for more information.

Introduction

I recommend hosting your new website with Bluehost, you can get a big discount by signing up with this link: https://www.bluehost.com/track/byol/byol_webess_48

You need to be a member to view comments.

Join today. Cancel any time.

Sign Up
Hey there, this video is going to be talking about the differences between JPEGs, PNGs, and SVGs. We'll even mention GIFs at the end. If you know all that you can skip on. We're not going to actually do anything in this class, a lot of me, talking and explaining, but if you've maybe never heard of an SVG, Scalable Vector Graphics, hang out, because this one is awesome. I'll show you an example, see, blurry PNG. Ah, really nice SVG, and it scales forever, watch, keep scaling in. Look how good he is. Let's jump in and figure all this out. 

Let's talk about the main image types, so JPEG, PNG, and SVG. So JPEG and PNG been around for a while. JPEG is probably the most common. So JPG, JPEG, whatever you want to call it. It is amazing for images like this; hi, Dan. Photographs do really well as JPEGs. Why? Because the file size is very small, in relation to the quality that you can get from it. So you can get something that looks really good, loads of colors, there's millions of colors in a jpg, but the file size in comparison is very, very small, so we use that. 

Where do JPEGs stop? And you're like, "So we would just use JPEGs for everything." The big trouble with JPEGs is that there's no transparency, you can't see through a JPEG. There's no way of having a hole in it to show things through, and that's where PNG starts. Now we'll look at our logo that we did. So this logo here, can you see, of Roar Bikes? It's actually an image, can you kind of see when I drag it around, it actually is see through. So I can change the color behind it and the color changes there. If this is a JPEG, pick a color for the background, and that would be it forever. 

So PNG is awesome, they have loads of colors as well. You can use millions of colors in a PNG, but it also has transparency. You might be saying, "Why don't we just use those?" Because the file sizes are huge for PNGs in comparison to a JPEG. So you got to do a trade-off, do I need transparency, if you do, then you have to leave JPEG behind. If you don't, like this image here, definitely a JPEG, because there's no transparency, so I might as well have all the goodness of the colors with the low file size. 

Now the third option, the SVG, is quite new. So if you haven't heard of this it's a Scalable Vector Graphic, and vector is the cool bit. So if you know about vector graphics you're going to go, "Really?" You can do vector online, you're just like, "You totally can." If you've never heard of vector before, you might search the term, it's vector, V-E-C-T-O-R. Because we won't cover it too much in here, but the benefit of it, as long as it's a really simple shape, like an icon or a logo, an SVG would be terrible for this, even if you wanted transparency, it will be terrible because there's just so much detail, but for simple shapes SVGs are brilliant. 

So logos here, we're going to switch this out for an SVG and look at the perks. So let's switch it out first and see the difference, and then we'll explain the perks for an SVG. So in your graphics, sorry, in your graphics? In your exercise files, so if you go to 'Exercise Files', 'Project2', There is our line, PNG, that we used earlier on. We're going to use this one called SVG, copy it, go to your Desktop, put it in your Project2 folder, in your images, and paste it in. Now in your code, go to Visual Studio Code. Here, under your Image tag, in your Logo div, switch out PNG for SVG. Let's have a little look at the difference.
 
So this is the original one, and get ready, look at the second one, ready, ooh, crisp and clear. So if you're working, you're obviously watching this video, sometimes, depending on your internet, sometimes people will write comments in the bottom, like, "It looks the same." You might be looking at a really low resolution of the video. Often if you check in the bottom right of your video you can like, raise or lower the quality of the video that you're watching, just so that you can see these details but let's make it a bit more obvious. So I can zoom in, so if I zoom in on this one, I'm holding 'Command +', hitting it a couple of times, that's on a Mac, 'Ctrl +' on a PC. 

I'm just zooming into my website, so that you can kind of see the real big difference. So a PNG uses pixels, to make its graphic, and while it was really small it was fine, had a slightly blurry edge, but vector, this SVG, it scales to infinity. You can scale it as big as you like, and the cool thing about it, is that it will always be crisp and clear on the outside, and still have a very small file size. You could get a PNG looking really good at this size, you could make it bigger and make it great, but the file size is going to get really, really big. 

So you'll find lots of websites now using SVGs. Browser compatibility is really good now, so if it's an icon or a logo, use an SVG, that's a good kind of blanket rule. If it's say an image, I'll show you a good example. So this one here, this is a graphic I made for a later part of the class, and let's say I want it to look exactly like this. My giant weird Meat Yoghurt that I made for you guys, but it's got a background color. This would work best as a JPEG. I'll show you how to export all these in a second, but let's understand them first. 

So this would work great as a JPEG because it's got lots of colors in here, and it's reasonably photographic, and the file size will be nice and small, but let's say I need it to have empty background, this little checker board things. The computer's way of saying there's nothing behind it. So this would have to be a PNG. Why wouldn't it be an SVG? An SVG needs that really simple details, if this was an SVG it just, file size would be huge and it would look terrible, and it just wouldn't work, I can't make this an SVG. So an SVG, perfect for this type of thing when there is like really simple lines. 

So anything done in Illustrator can be exported as an SVG, because that's really basic. Basic shapes, simple colors, easy. JPEGs for images, PNGs for images that need transparency, and anything that is really simple lines, like icons and small little graphics, arrows, that sort of thing, would be perfect for an SVG. You're like, "Has he mentioned GIFs?" GIFs, the only reason you use GIFs these days, if you need to animate them. GIFs have a real big drawback as in the-- they only have 256 colors, which is a pain. 

So you only can do small things, and the colors can't be too broad, and just there's no reason to use it unless you want to animate it. And even then, animating GIFs, a really niche kind of use case. You can animate in CSS and lots of other better ways. So I'm not going to cover GIFs here. I do cover it a lot more in my other, say Photoshop and Illustrator classes. We make all sorts of animated GIFs there, but we're not going to use a kind of traditional Web Design now. What I'll do is, now you understand the stuff, I might actually shift the next part of this video to another video, so that you can just watch that nice and by itself. So later on you can come back, just show you how to kind of export these SVGs, PNGs, and JPEGs easily. So let's do that in the next video.