<img>is used to include an image in the displayed page. All browsers will handle images encoded using the standards known as GIF (Compuserve Graphics Interchange Format), JPEG (Joint Photgraphic Experts Group) and XBM (X-Windows Bit Map).
It is important to realise that an in-line image is just that, in-line and is part of the current line of text. For many applications it is useful to include the <img> tag within <p> ... </p> tags so that it behaves like a block item.
The <img> tag has a number of attributes.
This is essential.
The value of the attribute is the URL of
the image. For example the following image
was included by the following HTML
<img src="envelop1.gif" alt="small envelope">
The value of this attribute controls the positioning of the image relative to the text. There no fewer than five standard distinct values defined in HTML 3.2 and several more non-standard values.
The top of the image is aligned with the top of the current line which, might, be the top of another image. Note that this does not, necessarily correspond to the top of the text on the line, an earlier image with different alignment may well specify a new top. If the image is taller than a line of text (which is normally the case), then following lines of text will appear beneath the image, i.e. the text does not "flow round" the image.
Here's an example of an image
presented with the align attribute set to top. You will see that
the top of the image is aligned with the tops of the letters.
There are two images in this line and
.
The Union Jack image has default alignment (bottom) and the top
of the little envelope is aligned with the top of the Union Jack which
is the highest point on the line.
The centre of the image is aligned with the base line of the current text line.
Here's an example showing the
effect of "middle" alignment
.
Many browsers understand the non-HTML 3.2 value center as
having the same meaning as middle.
This is the default alignment, i.e. what happens if you omit the align attribute.
Here's an example showing it in operation. The Union Jack image, which
should appear on the next line of text unless you've set your
browser incredibly wide, has its align
specifically set to bottom.
Notice that the bottom of the image is aligned with the base line of
the text not the base of the text descenders.
This alignment places the image at the left hand margin of the page with the text to the right of the image.
Here's an example.
This is the nearest normal HTML gets to flowing text around images and
the use of left (and right) aligned images is recommended for
most normal work illustrated with small in-line images.
Left and right aligned images used this way are far less disruptive of
the normal flow and presentation of text.
Some older browsers may not support left and right alignment.
By default there should be a small amount of space between the image and the text on its immediate right hand side if the text is left aligned, such space can be created by using the hspace of border attributes.
This is similar to left alignment. The previous example is repeated. Note that the ragged right alignment of the text makes the use of a small right aligned image less effective than left alignment.
Here's an example.
This is the nearest normal HTML gets to flowing text around images and
the use of left (and right) aligned images is recommended for
most normal work illustrated with small in-line images.
Left and right aligned images used this way are far less disruptive of
the normal flow and presentation of text.
The same repeated with right aligned text.
Here's an example.
This is the nearest normal HTML gets to flowing text around images and
the use of left (and right) aligned images is recommended for
most normal work illustrated with small in-line images.
Left and right aligned images used this way are far less disruptive of
the normal flow and presentation of text.
The non-HTML 3.2 values texttop, baseline, absmiddle and absbottom are recognised by most browsers but the interpretations vary widely. The theory seems to be that
The effects of the various alignments depend on the relative sizes of images and text.
If an image is being used as a link, i.e. included within <a> .. </a> tags with an href attribute then this attribute can be used to control the coloured border that will be drawn round the image.
Here's an example showing the small envelope again.
The border attribute is set to 5.
The value of the attribute is the border width in pixels.
The border can be suppressed entirely by setting the value of the border attribute epxlicitly to zero. This is useful if the image is an irregularly shaped image that merges into the background by being "transparent", however under these circumstances it is important to give users some other clue that the image is a link and can be clicked on.
In the absence of a specific setting of the border attribute
most browsers will generate a border whose width is
browser specific as is
illustrated here
The effect of using the border attribute on an image that
isn't a link is unclear.
Here's our little envelope again, this time not as a link but with
the border attribute set to 5.
These attributes can be used to instruct the browser to, effectively, expand or contract an image to a particular size in pixels. The width and height are expressed as decimal integers. The HTML 3.2 standards simply indicates that these attributes are used ot indicate the amount of space to reserve for the image, the expansion of the image to fill the space available is implicit.
On most browsers, if only one of width and height is specified the other value is automatically adjusted to preserve the aspect ratio of the image.
Here's the little envelope subjected to this treatment
with height set to 40 and width to 120.
This may be useful if you want a small image to fill a large
area but the pixels are likely to become very visible giving
a rather crude appearance.
Some browsers allow the value of the width attribute to be specified as a percentage of the window width, this results in an image whose size changes as the window size is changed. Here's an example, try resizing your browser window.
It is possible to stretch the image one way or another by changing the aspect ratio. With normal images this is not really useful however if the image is a simple block of colour then stretching it one way or the other can be used to created coloured bars without having to create and download lots of similar images. This can be used to create simple histograms in conjunction with the <table> tag.
These attributes control the total amount of space to be allocated to the image. The general effect is to put a border around an image. The values are quoted in pixels and specify the width (and height) of the border.
Here's the little envelope displayed with hspace set to 60
and vspace set to 40.
This is used to present alternative text to browsers that do not have image capability, have image capability turned off or to show what is happening whilst images are downloaded. The text is also useful for visually handicapped users and may also be of interest to searcg engine indexing programs.
The value of the attribute is simply the text. This can, most usefully, give some indication of the size and nature of the image. Many browsers will display the text when the cursor is held over the image and the mouse clicked.
This is a rather useful attribute that is not part of the HTML 3.2 standard. The purpose of the tag is to allow a "low-resolution" image to be displayed whilst the final "high-resolution" image is being down-loaded. The value of the attribute is, of course, the URL of the low-resolution image.
A typical example shows first a low-resolution monochrome image that requires a 35223 byte download, this is then overlaid with the high resolution colour image that requires a 449338 byte download. The low-resolution image was derived from the high-resolution by various pieces of image manipulation software. Seen down anything other than a very fast line this is very effective.
If your browser doesn't support lowsrc you can achieve a similar effect by combining the images in a non-looping animated GIF image. This, however, lacks the progressive rendering of the coloured image over the black and white background that makes the lowsrc version so attractive.
The effect of including two adjacent images varies slightly, some browsers will present the two images without intermediate space, some will only do this if there is no space between in the HTML between the two <img> tags. Here are two Union Jacks
The biggest variations concern alignment using the non-HTML 3.2 values. The variations in behaviour seem so complex and subtle that the only sensible advice is to avoid these values.
OP2 has some problems with left aligned images not lining their left edges up correctly with the current text indent.
The handling of image borders is rather variable, ARA and IE4 produce borders of text or link colour depending on whether the image is included with an <a> container (i.e. is a link). NN3 also attempts to do this but seems, sometimes, not to draw the complete border. MOS3 and IE3 draw an invisible border for a normal image, IE3 draws a full width link colour border, MOS3 draws a single pixel wide link colour border outside the invisible border. OP2 draws a sort of 3D effect border with a single pixel wide link colour extra border for links.
MOS3 didn't honour the hspace and vspace attributes. ARA didn't preserve the aspect ratio if only one of hspace and vspace was specified. MOS3 didn't allow image width to be specified as a percentage and IE seemed to have a bug that resulted in resizing only working if the image was in about the first 50 lines of the file.
NN, IE and OP2 don't butt up images if there is an intervening space between the <img> tags, MOS3 and ARA butted up images even in the presence of an intervening space.
Only NN supports the lowsrc attribute.