News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

HTML lesson - how to include images in web pages part 1

Started by ben2ong2, October 03, 2006, 06:10:50 PM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

ben2ong2

Including images is very simple. You employ the <IMG> tag. The required attribute of this tag is SRC, which takes the value of the image file's URL.

<IMG SRC="ash.jpg">

The SRC attribute determines the source of the image file and takes a URL as value. I have used a relative URL which shows that ash.jpg is located in the same directory as this file.

Three kinds of images files .gif, .jpg and .png are used on the Internet. A general rule of thumb is to use .jpgs for photographs and .gifs for images containing large blocks of single colors.

The <IMG> tag has many attributes

WIDTH: used for specifying the width of the image
HEIGHT: specifies height
BORDER: displays a border around the image
ALT: helps to insert a descriptive text for users using text based browsers or for visitors with visual disabilities.
HSPACE: inserts space at the left and right of the image
VSPACE: inserts space at the top and bottom of the image
NAME: gives a name to the image; necessary for client-side scripting using JavaScript
LOWSRC: provides a method through which a low quality alternate of the image is displayed first before the final one starts to load.
ALIGN: aligns other HTML elements such as text around the image.


The size attributes, WIDTH and HEIGHT
The WIDTH and HEIGHT attributes take pixel dimensions of the image as values. You can find the width and the height of the image in pixels using a graphics program such as Paint Shop Pro or Adobe PhotoShop.

Your image will display correctly even if you skip using these attributes. However, you should ALWAYS include them as this helps the browser window to allocate space for your image.

The image is distorted! It means that the width and height attributes force the image to be displayed in that space regardless of what the actual dimensions are.



BORDER attribute
Use this attribute to put a border around the image. The attribute takes a number as value. This number determines the thickness of the border in pixels.


ALT attribute
According to the World Wide Web Consortium, the ALT atribute is now required. You can put some advisory text with the use of this attribute. This text is displayed when the mouse pointer is placed on the image. You should get into the good habit of including ALT tags. Why? Read on...

Visitors using text-based browsers or who have turned off images in their browsers will not be able to see the image. However, they would be able to read the image description through the ALT attribute. Also, the ALT attribute value will be read by speech browsers, employed by visually impaired visitors. So be a good developer and insert the ALT attribute always.

You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login