Using Images

Course Outline


Adding Images To Your Pages


Whether they are used as illustrations on a page, as background, or as links, images can add style and pizzazz to a site.

Everyone wants a cool site... and part of cool is incorporating good, useful graphics. Well-used graphic images make the site more interesting, add information, and help with navigation.

With a little forethought, you can use images that pull in quickly, display quickly, look good, and add value to your site. On the flip side, images can also make your site a big, unwieldy bandwidth pig.

The Image Tag (<img src="filename.gif" align=left/right width=XXX height=XXX alt="text">)

You add images with the image tag. The image tag tells the browser to display a specific image at this point in the page. The image tag inserts an image and is used just once.

The location of the image is described by its URL. For example, this code tells the browser to insert an image called "earth.gif" into the file. The other attributes in the image tag describe how to place the image on the page.

The image tag has six basic attributes:

  1. src. Source. This is the location and name of the image you are using. As with anchors and links, use the full URL if the image is on another server. Use relative URLs if it is within your own site. Remember that the URL must begin and end with quotes.
  2. align. Alignment. You can align the image to the right or left side of the page. You cannot center it with the align attribute. (If you want to center it try this trick: put a center-aligned paragraph tag above the image.)
  3. width. Width of the image in pixels.
  4. height. Height of the image in pixels.
  5. border. Width of the border around the image in pixels. Use the border command only when the image is also the anchor for a link.
  6. alt. Alternate text. This is the text that appears in a reader's browser if the reader has his or her image loading turned off or if the browser doesn't display graphics. You should always include some brief alternate text. Remember that the text must be surrounded with quotation marks.

Using Width and Height Attributes:

Technically you don't have to specify the exact width and height of your images, but you should. Specifying image width and height lets the browser layout the page and begin displaying the text while it is still downloading the image. The reader can start using the page immediately instead of waiting for all the images. This increases perceived speed and makes your readers feel like your site is fast.

Specify image size in pixels. Use your graphics program to see the size of the image in pixels. Save the image file at the exact size you want to use. Although most browsers will scale the image if the image file and your specified size are different, rescaling consumes computer processing time. Picture the poor reader out there with a 486 PC and 8 megs of RAM watching the computer go chug-a-chug-a-chug-a as your image rescales on his or her screen. It is not a pretty sight.

Back to top of page

Using the Image as a Link

You already know how to create a hypertext link. Instead of a using a piece of text as the linked item, you can also use an image.

To link to an image simply substitute the image tag for the text between the on and off anchor tags. The following example shows how to link to the file "frogs.html" using both a text link and an image link. First, we'll create a text link, like this:

Frogs are your friends.<br>
<a href="frogs.html">Look at the frog!</a><br>
Ribbet. Ribbet.<br>

which displays like this in a web browser:

Frogs are your friends.
Look at the frog!
Ribbet. Ribbet.

Using the Break Tag with an Image (<br clear=right/left/all>)

When working with images, you sometimes want the text to follow below the image rather than run alongside the image. The break tag <br> lets you do this.

Usually the break tag stands on its own without any attributes. However, the tag does offer one attributes, clear.

Clear tells the browser to display the content which follows it below the lowest part of the image. By putting a break tag with the clear switch set after a graphic, you ensure that the text that follows the graphic appears underneath the graphic rather than beside it.

The clear attribute has three possible values:

  1. clear=left tells the browser to look to the leftmost side of the page and drop the text below the item there.
  2. clear=right tells the browser to look to the rightmost side of the page and drop the text below the item there.
  3. clear=all tells the browser to look to all across the page and drop the text below the lowest item on either side.

Back to top of page

Images

Inline Imagesfern

bulletare loaded automatically with the Web page
bulletappear on the loaded Web page
bulletunless Image Loading is turned off

 

External Images Fern Image

bulletare not displayed when you load the Web page
bulletare loaded on demand by the user clicking a link
bulletdon't need a graphical browser, can be viewed with an image editor after downloaded

There are two widely-used image formats: GIF and JPEG

GIF - Graphical Interchange Format

bulletCompuServe GIF or GIF87 orGIF89a
bulletgood for simple images and icons
bulletlimited to 256 colors
bulletgrainy quality for photographs
bulletthe compression doesn't lose bits of the image as it compresses

 

JPG files - Joint Photographic Experts Group

bulletgood for photographs
bulletmillions of colors
bulletsmall sizes for photographs
bulletcompression throws out bits of the image as you make the file smaller
bulletnot good for simple images

Back to top of page

Tags for Inline Images

bulletYou can display an inline image with <IMG SRC=...> tag.
Example: <IMG SRC="ferntile.gif">

bulletYou can turn an image into a link.

bulletThe image becomes the clickable hyperlink and has a border around it.
Example:
<A HREF="cis114.htm"><IMG SRC="frog.jpg"></A>

bulletIt's a good idea to include an alternative to the image for those with text-only browsers.
Example:
<A HREF="cis114.htm"><IMG SRC="frog.jpg" ALT="[picture of frog]"></A>

bulletYou can align the text and the images. These tags are designed to wrap the image within one line of text.
Example:
<P><IMG SRC="fern.jpg" ALIGN=MIDDLE>A Green Fern</P>

bulletYou can also adjust how close the picture is to the text using VSPACE and HSPACE attribute.
Example:
<IMG SRC="ferntile.jpeg" VSPACE=30 HSPACE=30>

bulletYou can adjust the image dimensions to make a small image bigger using WIDTH and HEIGHT.

This makes Web pages appear to load faster since it makes space for the image and lets text load.
Example:
<P>Inline Images <IMG SRC="ferntile.gif" HEIGHT=32 WIDTH=32></P>

bulletBy default, images without a link will have no border. You can add one with the BORDER= tag . However, this may make the user think it is a link.

BORDER=0 (no border) BORDER=5 (border which is 5 pixels wide)

Back to top of page

What is the impact of loading images in your Web page?

bulletlarge graphic files take a long time to load
bulletkeep total image file size less than 60K per page

Some Hints for Better Use of Images

bulletKeep your file size small
bulletReduce the number of colors which greatly reduces file sizes
bulletUse thumbnails to link to larger  images

ferntile.gif (2907 bytes)This .gif thumbnail is only 3K. The external .jpg is 8K.

 

Background Colors

bulletIt is best to specify colors via the RGB (Red, Green, Blue) values 0-0-0 to 255-255-255
bulletColors can be identified using hexadecimal color descriptions (255=FF) .
bulletNeed to see an Index of color codes?
bulletColor names may not work in older browsers, so using the hexadecimal color code is preferred.
bulletYou can also change the color of an individual word using the FONT attribute.

Image Backgrounds

bulletCreated by repeating (tiling) the image across the browser window.
bulletNeed to eliminate seams so you have a clean tile pattern.

 

Finding Images on the Web

bulletIcon and Image Bazaar
bulletBarry's Clip Art has lots of free animations
bulletImages from Rutgers
bulletHTML GURU icons and images
bulletEveryicon

You could also do a search for "Clipart" and be presented with numerous links.

Cautions about using Clip Art

bulletRemember about copyrights.  We will be talking about copyright laws and web images later in the course.
bulletRead the license agreement.

Better Yet - create your own images!

Back to top of page

Course Outline

Nancy Bryant