HTML Images
In HTML, images are defined with the <img>
tag, which is empty because it contains attributes only and has no closing tag.
To display an image on a page, you need to use the src
attribute.
src
stands for “source.”
The value of the src
attribute is the URL of the image you want to display on your page.
The syntax and an example are given below.
The URL points to the location where the image is stored.
HTML Syntax |
HTML Script |
Web Display |
<img src="url">
|
<img src="smiley.gif">
|
|
An image named “
smiley.gif
” has the URL:
http://undcemcs01.und.edu/~wen.chen.hu/figure/smiley.gif
The browser puts the image where the image tag occurs in the document.
If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph.
†If an HTML file contains 10 images—11 files are required to display the page right.
Loading images take time, so use images carefully.
The alt Attribute
|
<img src="smiley.gif" alt="Face">
|
|
The
alt
attribute is used to define an “alternate text” for an image.
The value of the
alt
attribute is an author-defined text.
The attribute tells the reader what he/she is missing on a page if the browser can not load images.
The browser will then display the alternate text instead of the image.
Including the alt attribute for each image can improve the display and usefulness of your document for people who have text-only browsers.
|
|
Tag |
Description |
<img> |
Defines an image. |
<map> |
Defines an image map. |
<area> |
Defines an area inside an image map. |
|
Demonstration
The following demonstration shows how the HTML script is displayed on the Web.