[Images]Imagine That! (Page 5 of 5)


The <IMG> Tag

Pictures are worth thousands of words, especially in terms of downloading. Images on your Web pages that are placed using the <IMG> tag are inline graphics that are downloaded when the page is loaded unless the reader has set their browser's preferences to not auto-load images. Not everyone can tolerate waiting for the next advertisement to pop up with its animated GIF banner. Some readers use browsers that do not even support images. Try to be considerate and tolerant when writing code and take these people into consideration.

Also be aware that different browsers will display text wrapping differently, monitors will display images differently based on preferences and number of colors available, and different browsers do not support all HTML commands. Your page may be displayed in a manner that may surprise you. Browsers that only support HTML 2.0 will constrain type to a single line on one side of an image. Readers with different fonts can have different vertical alignments.

It is wise to test your pages in a number of different browsers before publishing them on the Web.

Enough lecture. Here is the <IMG> tag and its attributes including:

Bacic <IMG> Tag Stuff

The basic code to display an image is:
     <IMG SRC="image.gif">
The SRC attribute is the URL of the image that is being displayed. The rules for pathnames of images are the same as for linking HTML pages. Let's go over that again, anyway, to beat it to death and prevent confusion.

An image can be in the same folder/directory as the HTML file that calls it.

An image can be in a different folder/directory (anywhere in the world) than the HTML file that calls it.

An image can be called by its exact and complete name (known as the URL or Uniform Resourse Locator). This is known as an absolute pathname (it must be absolutely correct!).

An image can be called by relative addressing (as in: go up one folder/directory and down again into the Images_Used folder/directory and the file is in there).

Relative vs. Absolute Naming Revisited

Absolute pathnames are not portable. If the file moves, your link will not work. If you make a mistake (anywhere) in the pathname, the link will not work. I would not reccommend absolute pathnames for general Web publishing, but for instances where there are security concerns or the files will not leave a corporate network. An example of an absolute link to a graphic is: Relative pathnames are very portable. The files can be copied from one place to another and the links will be retained. Here are some examples:

Vertical Alignment Attributes

There are several options for vertical alignment:

Vertical image alignment: ALIGN=TOP

Aligns the top of the image with the topmost element in the line:

Vertical image alignment: ALIGN=MIDDLE

Aligns the center of the image with the middle of the line of type. The middle of the line of type is usually calculated from the baseline, so the visual effect is usually not exactly what you would expect it to be; the type does not appear to be perfectly vertically centered to the image. This is more noticeable with larger type:

Vertical image alignment: ALIGN=BOTTOM

Aligns the bottom of the image with the bottom of the line of text:
Other supported attributes include:

Vertical image alignment: ALIGN=TEXTTOP

Aligns the top of the image with the top of the tallest text element in the line of type (where ALIGN=TOP references the tallest element overall, other images included):

Vertical image alignment: ALIGN=ABSMIDDLE

Aligns the center of the image with the center of the largest element in the line (where ALIGN=MIDDLE usually uses the baseline of the text as a reference):

Vertical image alignment: ALIGN=BASELINE

Aligns the bottom of the image with the baseline of the text:

Vertical image alignment: ALIGN=ABSBOTTOM

Aligns the bottom of the image with the bottommost element in the line (although when type is involved, usually the baseline of the type is used):

Horizontal Alignment Attributes & Text Wrap

It is important to remember that not all readers will see your page through the same Web browser and some variation is to be expected. Try to plan for it in your design. Older browsers (HTML 2.0) especially only allow one line of type on either the left or the right of an image. Newer attributes for text wrap include:

Horizontal image alignment: ALIGN=LEFT

Positions the image on the left side of the Web page with text to the right:
[GIF Image]Imagine That! Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.

Horizontal image alignment: ALIGN=RIGHT

Positions the image on the right side of the Web page with text to the left:
[GIF Image]Imagine That! Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.

Stopping Text Wrap

Once you start wrapping text, the Web browser will continue to wrap all images until there is a bit of code to tell it to stop. The code is similar to the <BR> tag used to force a line break, with some flexibility:

Stop image alignment: BR CLEAR=LEFT

This code forces the Web browser to break to a new left margin (below the image) if the image is ALIGN=LEFT. If the image is ALIGN=RIGHT, the attribute seems to have no effect. Remember, results may vary:
[GIF Image]Imagine That!
NOTE: CLEAR=LEFT with the IMAGE on the LEFT WILL STOP text wrap. Remember that a paragraph of type may display differently in another Web browser. There are a number of instances where only a single line of type will display next to the image and the rest of the paragraph will be pushed to a new line that will start below the image.
[GIF Image]Imagine That!
NOTE: CLEAR=LEFT with the IMAGE on the RIGHT WILL NOT STOP text wrap. Remember that a paragraph of type may display differently in another Web browser. There are a number of instances where only a single line of type will display next to the image and the rest of the paragraph will be pushed to a new line that will start below the image.

Stop image alignment: BR CLEAR=RIGHT

This code forces the Web browser to break to a new left margin (below the image) if the image is ALIGN=RIGHT. If the image is ALIGN=LEFT, the attribute seems to have no effect. Remember, results may vary:
[GIF Image]Imagine That!
NOTE: CLEAR=RIGHT with the IMAGE on the RIGHT WILL STOP text wrap. Remember that a paragraph of type may display differently in another Web browser. There are a number of instances where only a single line of type will display next to the image and the rest of the paragraph will be pushed to a new line that will start below the image.
[GIF Image]Imagine That!
NOTE: CLEAR=RIGHT with the IMAGE on the LEFT WILL NOT STOP text wrap. Remember that a paragraph of type may display differently in another Web browser. There are a number of instances where only a single line of type will display next to the image and the rest of the paragraph will be pushed to a new line that will start below the image.

Stop image alignment: BR CLEAR=ALL

This code forces the Web browser to stop text wrap regardless of whether the image is on the left or the right. The code is similar to CLEAR=LEFT and CLEAR=RIGHT:
The results are shown above. The command <BR CLEAR=ALL> was used after each example.

Adding Space Around Images

Images can stand out more and have greater impact with the use of "white" space around the image. This can be done with the HSPACE and VSPACE attributes. These attribute are used to specify the number of pixels of white space to the left/right or above/below an image:
They can be used by themselves or together The sample code is shown next is included to give an idea of what the default settings for your browser will display without the HSPACE and VSPACE attributes: [GIF Image]Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.

Adding space around images: HSPACE

Use this attribute to specify the number of pixels of white space to the left/right an image:
[GIF Image]Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.

Adding space around images: VSPACE

Use this attribute to specify the number of pixels of white space above and below an image:
[GIF Image]Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.

Adding space around images: Using both HSPACE and VSPACE

The attributes can be used together as demonstrated in the following example: [GIF Image] Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.
[GIF Image] Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.

Combinations Of Attributes

Browsers today are not likely to support some combinations of attributes and the results can be unexpected. Again, test your pages in several Web browsers before publishing. Here are a couple of examples of attribute combinations:: [GIF Image] Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.
Remember that a paragraph of type may display differently in another Web browser. Some Web browsers and those supporting older versions of HTML (HTML 2.0) will only allow a single line of type to be displayed next to an image and the rest of the paragraph will be pushed to a new line that will start below the image. This is usually not desirable but your page may attract readers who will see you page in this fashion. It is not always possible to design perfect layouts for all browsers, but it is important to be aware that this type of event is possible. One of the best ways to prepare your pages for the Web is to preview the pages in a variety of browsers to see for yourself how the presentation will appear.[GIF Image]

Scaling with the HEIGHT and WIDTH attributes

Your pages can load a little faster with the help of the HEIGHT and WIDTH attributes. This works because the browser will create a space for an image the size of the number of pixels specified by HEIGHT and WIDTH (instead of waiting until it reads that information from the image itself) and continue to format the page around this space.

Browsers that do not support HEIGHT and WIDTH will ignore the commands, so it doesn't hurt to use them, but it does imply that you know the size that the image will be when it is created and displayed.

If the size of the actual image does not match the size of the HEIGHT and WIDTH size in pixels, the image will be scaled. Scaling an image up to a larger size can make an image look pixelated or bitmapped, while scaling an image down will make it look smoother.

Scaling images down will take longer to load than an image scaling up because of file size.

Example of HEIGHT and WIDTH attributes
[GIF Image]
Code: <IMG SRC="Q.gif">
(Graphic is 72x72 pixels at 72dpi shown 100%)
[GIF Image]
Code: <IMG SRC="Images.gif">
(Graphic is 72x44 pixels at 72dpi shown 100%)
[GIF Image]
Code: <IMG SRC="Q.gif" HEIGHT=36 WIDTH=36 >
(Scaling to 50%)
[GIF Image]
Code: <IMG SRC="Images.gif" HEIGHT=22 WIDTH=36 >
(Scaling to 50%)
[GIF Image]
Code: <IMG SRC="Q.gif" HEIGHT=144 WIDTH=144 >
(Scaling to 200%)
[GIF Image]
Code: <IMG SRC="Images.gif" HEIGHT=88 WIDTH=144 >
(Scaling to 200%)
[GIF Image]
Code: <IMG SRC="Q.gif" HEIGHT=88 WIDTH=144 >
(Anamorphic scaling)
[GIF Image]
Code: <IMG SRC="Images.gif" HEIGHT=144 WIDTH=144 >
(Anamorphic scaling)


Providing A Clue Without a View:
The <ALT> Tag

Many individuals bent on speed will not auto load images or will use text-only browsers to get through the Web as quickly as they possibly can. Sites that do not provide them with options to navigate will be lost on them. Use the <ALT> tag to give your readers a way to navigate your pages.

The following is an example of what a Netscape browser would display for a missing link: Use of the <ALT> tag gives the reader an idea of the content of the image, which may be especially useful for icons such as "HOME", "BACK", etc. [ Personally, I like to put my ALTs in square brackets ]

Borders

Normally, an image on a web page will not have a border unless it is a link as shown below: The width of the border of an image can be changed or removed as shown:

Fast Previews With The LOWSRC Attribute

If you are looking to optimize your Web page, the LOWSRC attribute could be for you. The idea is to get the browser to load a very low resolution image on the first pass and after the page is initially loaded and displayted, the image specified as the high resolution image by the SRC attribute is loaded and fades in to replace the LOWSRC image. This is entirely optional and older browsers ignore LOWSRC.

There are different ways to work with LOWSRC:


[Top] [Back] [Next] [Main Menu] [Index]
[ Basics ] [ Text ] [ Images ] [ Links ] [ Tables ] [ Forms ]
©Ken Kaleta 1997, 1998, 1999