Tag: images

HTML – Images

To add a picture to a HTML page we use the <img> tag. This tag creates a holding space for the image to be included on the page. This tag does not need to be closed.

The tag uses a number of attributes but two of them are required.  SRC tells the browser the location and file name of the image file (its source). ALT is the alternative text that is displayed if the picture fails to load.

Homer at computer

So the HTML code to display the image above is

<img src=”HScomp.jpg” alt=”Homer at computer”>

This assumes that the image is in the same folder as the HTML file.

If the image is the wrong size then you can use the height and width attributes to scale the picture.

<img src=”HScomp.jpg” alt=”Homer at computer” width=200>

Would make the image 200 pixels wide while keeping the aspect ratio correct by automatically scaling the height by the correct percentage.