02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Defining HTML Image Width and Height

Although we don't recommend changing image sizes dynamically as it lowers the quality of your image or adds extra loading time that isn't needed lets talk about it a bit...

Video Transcript

00:00Welcome back, how is it going so far, mom ? -okay
00:09sometimes we want to define a size for our image,
00:08the next thing that we're going to do is...
00:04Great! So you're getting the basics. You know how to put an image into a site,
00:17you want to make sure that there's a certain amount of space there for that image
00:12a lot of times in a email newsletter, when you want to send an email,
00:20Even if the image doesn't load,
00:22and a second way is maybe you want to resize the image
00:25now I don't really suggest you to resize images dynamically because if this is a big file size
00:32and you're making it smaller it's a still big file size,
00:34and you're forcing people to download something bigger than they should
00:38We're going put it onto the side let's see how to do it.
00:43We just go into our image, and I'm breaking a line, it doesn't really matter, you could break a line
00:48you could not break a line, HTML doesn't care about breaking the lines nor does it care about spacing
00:52or tabs so build it out the way that's comfortable for you,
00:55We're going to add a new attribute 'width'
00:57and in it, I'm going to put a number,
00:59you'll see that with a number I usually just put a value right up ahead and I don't put around double quotations,
01:07or quotations because it's a number and a number isn't a string
01:12Although we're not programmers, this is considered a string in HTML and any programming language
01:19It is because their spaces in between, we have to have a way to tell the alt attribute
01:24that it starts here and it ends here,
01:26That was the reason why we used that double quotation,
01:29Now with numbers there will never be a space in numbers,
01:32so it's not that important to put it in
01:35It is legal in HTML to put a double quotations around it but it's not needed
01:40because it's very clear for the width what the width is,
01:43contrary to the 'alt' if I put here a space without this
01:46you would also see it where your code ends
01:48well maybe this is an attribute as well, just as the source was. There's no way for the browser to know
01:54so we're basically contain our text telling: here's where we started our text,
01:58here's where we end it and all this belongs to our 'alt' attribute,
02:02-does it make sense? -yeah
02:04And now that we force a 'width' to our image, just by putting a width and saving our file,
02:09if we go into our browser and click on refresh,
02:12you'll see that the image is going to re-size. It's going to adhere to the rules of the height of the element,
02:18but it's going to be now smaller,
02:20but if we force the height as well, we'd shrink down and shrivel down the image
02:24and kind of like smash it up together like a sandwitch
02:27which we could do that if we wanted to,
02:29so we could go to our height as well, and set the height to be 50
02:34and if we do that and go into out browser we'll see that our image is going to be, every aspect of the image
02:38will be there but it's going to be smashed up,
02:41That's not something what we want to do but it's something that we could do,
02:45by the way same rule applies if we want to set a height and we want to make sure that the height is 200
02:51but we don't want to put a width at all inside,
02:53that's completely fine as well,
02:55It would then create a perfect size image that its height is 200
03:01well, it was 200 before I zoomed in, so let me go back to the actual size
03:07and that's how we add images in HTML, very simple
03:10very easy and my mouse for some reason really loves zooming in
03:13and I don't know how it does it but we'll ignore that
03:16So we learnt about height, we learnt about width, let me leave both of them
03:20so you guys could see them when you download the source files and you're playing around with it
03:24and that's all I have to say about the image attributes,
03:27now before I move on to other topics,
03:29I really want to dedicate some times to understanding how file structures work
03:34because with the file structures we'll be able to be more efficient with our image processing,
03:40In our next video we're going talk a little bit about URLs and images in general
03:47Let's move on into our next video

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!