Lecture 9: Images

Overview:

  1. Images on the Web
  2. The <img /> Tag
  3. Images and Text
  4. Recommendations and Considerations

Images on the Web

The <img /> Tag

Attribute Usage and Effect Values Accepted Default Deprecated?
align Used to horizontally move the image (text then wraps around the edge of the image) or to vertically align text relative to the image left | right | bottom | middle | top bottom Deprecated
alt This is a required attribute and is essential for accessibility, as the alt attribute's value is read/output by adaptive technology such as screen readers and braille output devices.

The alt content will display when images are disabled in the browser or when images fail to load for some reason (e.g., a broken path to the image).

If the image has no meaning to the user or is used for formatting (such as a block of color), indicate alt="" so that adaptive technology skips over it; if you omit the attribute the file name is read/output and that is usually confusing.

Alt attributes display as tooltips in Windows Internet Explorer 5.x and up, as well as in some old browsers.
Text   Not deprecated
border If an image is linked (surrounded by <a> </a> tags), a blue border will appear around the image. This attribute determines how thick that border is, ranging from 0 (no border) to a number greater than zero that represents the border width in pixels.

Unlinked borders tend to render as black.
Number Typically 1 or 2 if linked (zero if unlinked) Deprecated
height Always specify a height so that images render faster. If the height is omitted the browser takes a couple of passes before determining the correct dimensions.

In almost all cases you should use the actual height of the graphic for the value; while you could specify a larger or smaller height to scale the image this will usually cause distortion.
Number   Not deprecated
hspace Horizontal space; this is the number of pixels to the left and right sides of the image; other content will not move into that space. Number   Deprecated
name This can be used in JavaScript to locate the image and modify the graphic. We will not be using the attribute in this class. Text   Not deprecated
src This required attribute provides the path to the image. Without this attribute, the <img /> tag could not work properly. Path to image; relative paths always preferred to absolute   Not deprecated
vspace Vertical space; this is the number of pixels to the top and bottom sides of the image; other content will not move into that space. Number   Deprecated
width Always specify a width so that images render faster. If the width is omitted the browser takes a couple of passes before determining the correct dimensions.

In almost all cases you should use the actual width of the graphic for the value; while you could specify a larger or smaller width to scale the image this will usually cause distortion.
Number   Not deprecated

Sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Images in (X)HTML</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <p>Picture 1 of the Sydney Opera House:</p>
    <p><img src="sydney1.jpg" alt="A picture showing part of the
    Sydney Opera House" width="113" height="150" /></p>

    <p>Picture 2 of the Sydney Opera House:</p>
    <p><img src="sydney2.jpg" alt="A view of the Sydney Opera
    House from a distance" width="113" height="150" /></p>

    <p>The above images are public domain images from
    <a href="http://www.burningwell.org/">BurningWell.org</a></p>
</body>
</html>

See how this example renders

Images and Text

Sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Images in (X)HTML, Part II</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <p><img align="right" src="sydney1.jpg" alt="A picture showing
    part of the Sydney Opera House" width="113" height="150" />
    Picture 1 of the Sydney Opera House</p>

    <br clear="all" />

    <p><img hspace="20" src="sydney2.jpg" alt="A view of the Sydney
    Opera House from a distance" width="113" height="150" />
    Picture 2 of the Sydney Opera House</p>

    <p>The above images are public domain images from
    <a href="http://www.burningwell.org/">BurningWell.org</a></p>
</body>
</html>

See how this example renders

Sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Images in (X)HTML, Part III</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <p><img align="left" hspace="30" src="sydney1.jpg" alt="A picture
    showing part of the Sydney Opera House" width="113" height="150" />
    Picture 1 of the Sydney Opera House</p>
    <p>Sample text</p>
    <p>Sample text</p>
    <p>Sample text</p>
    <p>Sample text</p>
    <p>Sample text to show wrapping around the image</p>

    <p><img align="middle" vspace="50" src="sydney2.jpg"
    alt="A view of the Sydney Opera House from a distance" width="113"
    height="150" />
    Picture 2 of the Sydney Opera House</p>

    <p>The above images are public domain images from
    <a href="http://www.burningwell.org/">BurningWell.org</a></p>
</body>
</html>

See how this example renders

Sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Images in (X)HTML, Part IV</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <p>Picture 1 of the Sydney Opera House
    <img align="right" border="15" hspace="5" vspace="5" src="sydney1.jpg"
    alt="A picture showing part of the Sydney Opera House" width="113"
    height="150" /></p>

    <br clear="all" />

    <p>Picture 2 of the Sydney Opera House
    <a href="http://www.sydneyoperahouse.com/"><img align="right"
    border="5" vspace="50" src="sydney2.jpg" alt="A view of the Sydney
    Opera House from a distance" width="113" height="150" /></a></p>

    <br clear="all" />

    <p>The above images are public domain images from
    <a href="http://www.burningwell.org/">BurningWell.org</a></p>
</body>
</html>

See how this example renders

Recommendations and Considerations

  1. You must always be careful of copyright when dealing with images. It is our professional, ethical, and legal responsibility to only use:

    • Images where you own the copyright (for example, pictures or art you have created)
    • Images in the public domain (these images can be freely used and will be what we use for this class; consult Wikipedia or a site such as BurningWell.org)
    • Images under some sort of licensing system (where you are meeting the licensing obligations, which could be as simple as citing the author/creator of the image)
    • Images you have purchased (such as from a photo disc or online at a website such as Getty Images)
  2. Quality images matter. Avoid clip art, ASCII art, and low-quality images. Your site's visual presentation reflects directly on your professionalism and credibility.
  3. At a minimum, always specify src, height, width, and an appropriate alt attribute value.
  4. Think carefully about the alt attribute value. In some cases alt="" is appropriate and should be used; in other cases you should provide meaningful text. Ask yourself what text would be helpful to hear aloud or have output in some other fashion to someone experiencing the site in a non-visual fashion.
  5. If an image cannot be found, some browsers will leave a placeholder for it (such as Windows Internet Explorer and Opera), while Gecko-based browsers render the layout as if the image was not there.
  6. Finding out image dimensions (height/width) has become easier over time. Windows XP will display the image dimensions in a tooltip and also at the bottom of the window if you select the image file. If you have an imaging program that can also give the dimensions. Mac users can drag images into their browser and look at the title bar to see the dimensions.
  7. Images must always be transferred as binary when you put them on the server.