From the course: HTML: Images and Figures

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Image size: Width and height

Image size: Width and height - HTML Tutorial

From the course: HTML: Images and Figures

Start my 1-month free trial

Image size: Width and height

- [Instructor] Sometimes an image won't be the size you'd like. Here's a webpage that shows a picture of cherry blossoms, but I'd like the image to be a bit smaller. I can change its display size by using the width and height attributes on the image element. First, I need to find out how big the image is right now. I can do that by right-clicking and looking at the image info. This image is 533 pixels wide and 400 pixels high. So let's say I wanted to display as 300 pixels high instead. I can go into the editor and add the height attribute to the image element by saying height equals 300. Just put the number as the attribute value. Don't use PX, that's for style sheets. When you save and reload in the browser, you'll see that the image is now smaller. I didn't have to specify the width. The browser made sure that the picture stayed in proportion. However, it's always a good idea to specify both the width and height. This lets the browser figure out how much space the image will need…

Contents