Web Images
Web Images
Things might seem a little bland and boring with all of this text formatting. Of course, the web is not
just about text, it is a multi-media extravaganza and the most common form of sparkle is the image.
The img tag is used to put an image in an HTML document and it looks like this:
The attribute tells the browser where to find the image. Like the tag, this can be absolute, as the
above example demonstrates, but is usually relative. For example, if you create your own image and
save it as “alienpie.jpg” in a directory called “images” then the code would be <img
src="images/alienpie.jpg"...
The width and height attributes are necessary because if they are excluded, the browser will tend to
calculate the size as the image loads, instead of when the page loads, which means that the layout of
the document may jump around while the page is loading.
The alt attribute is the alternative description. This is an accessibility consideration, providing
meaningful information for users who are unable to see the image (if they are visually impaired or
have disabled images in their browser, for example).
Note that, like the br tag, because the img element does not enclose any content, no closing tag is
required.
The construction of images for the web is a little outside of the remit of this website, but it is worth
noting a few things…
The most commonly used file formats used for images are JPEGs, GIFs, and PNGs. They are
compressed formats, and have very different uses.
A JPEG (pronounced “jay-peg”) uses a mathematical algorithm to compress the image and will distort
the original slightly. The lower the compression, the higher the file size, but the clearer the image.
11
JPEGs are typically used for images such as photographs.
A GIF (pronounced “jif”) can have no more than 256 colors, but they maintain the colors of the
original image. The lower the number of colors you have in the image, the lower the file size will be.
GIFs also allow any pixel in the image to be transparent.
GIFs are typically used for images with solid colors, such as icons
or logos.
A PNG (pronounced “ping”) replicates colors, much like a GIF, but allows 16 million colors as well as
alpha transparency (that is, an area could be 50% transparent).
12