|
Search This Site
|
Images in HTML
The src AttributeThe source attribute ( src ) is used to specify the location of an image. In the code snippet below, it is assumed that the image is located in a folder named images. It is also assumed that the name of the image is flower. In order for the browser to display the image it has to check the folder for it. All this is specified by the src attribute. You will also note the file extension .jpg. The file extension of the image you wish to display must be specified.
Other common extensions include .gif ( often used for graphics ) and .png. Using the src attribute to apply the image:
<img src="images/flower.jpg"/>
Note: Remember the source attribute is images/flower.jpg because the flower image is located in a
sub-folder. This sub-folder has the name images. If the flower image was in the same folder as the HTML file it is being applied to then the src
would instead be flower.jpg. The alt AttributeThe alternate attribute ( alt ) displays a text description in browsers that are unable to
display the image. The alternate text attribute applied:
<img src="images/flower.jpg" alt="A Hibiscus Flower"/>
Note: In HTML 4.01 any image used without the alternate text attribute generates an error when the code is validated.
The title AttributeThe title attribute is used to provide information about an image. When the mouse points on or passes over the image the title is
shown. Applying this attribute:
<img src="images/flower.jpg" alt="A Hibiscus Flower" title="Hibiscus Flower">
Note: The title attribute is just as important as the alt attribute. Make use of it when using images in HTML. The width and height AttributesWidth and height are also used in images. Observe: <img src="images/flower.jpg" alt="A Hibiscus Flower" title="Hibiscus Flower" width="200px" height="100px"> Note: The width and height attribute can be used to resize an image. This method is however highly discouraged as the browser still
has to load the original size. So if the image is really large and you resize it with the width and height attributes it may still take some time to load.
You should instead consider resizing the image using a editing program. One such program is Microsoft Paint. Images as LinksImages can also be used as links. If you have not went through the links lesson as yet you may do so now. <a href="http://www.new2html.com/html_images.html"> <img src="images/flower.jpg" alt="A Hibiscus Flower" title="Hibiscus Flower" width="55px" height="55px"> </a> Practise Excercise
Instructions
Previous Lesson - Links
Next Lesson - Tables (Part 1)
|
|
© Copyright 2010 | All Rights Reserved
|