EIW Fall 2003 Lecture Notes

HTML and Images


The IMG tag

You can include images in your HTML document using the IMG tag. The actual images themselves can be anywhere on the WWW, so your web page can include images that come from another site. The IMG tag has one required attribute - the SRC attribute specifies the URL that contains the image. Typically the URL will indicate a static file that contains either a GIF or JPG image (two standard file formats for images)

.

A simple example of an IMG tag and what this looks like when the browser renders it:

Here is my image: <IMG SRC=cookie.gif>
  

Here is my image:

There are a number of optional attributes to the IMG tag that can alter how the image is rendered by the browser, some are listed below.

Images as links

Images can be hyperlinks, all you need to do is put the IMG tag between the <A> tag and it's end tag </A>. Here is an example:

Press the cookie to go to cookie.com
<A href="http://www.cookie.com">
<IMG SRC=cookie.gif>
</A>

rendered will look like this:

Press the cookie to go to cookie.com

IMG tag optional attributes:

Image File Format: GIF vs. JPG

The two image file formats supported by most browsers are GIF and JPG (pronounced jaypeg), and there are differences you might want to be aware of.

GIF JPG
Max. # of colors 256 Tens of thousands
Compression Lossless compression
(doesn't compress much, but nothing is lost)
Great compression,
but with some loss
Transparency Yes NO
Interlacing Yes NO
Animations Yes NO

Generally GIF format is used for icons, drawings and anything requiring animation. JPG is typically used for photographs.