|Always specify the width and height of an image. If width and height are not specified, the page will flicker while the image loads.|
In HTML, images are defined with the <img> tag.
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
The src attribute specifies the URL (web address) of the image:
The alt attribute specifies an alternate text for an image, if the image cannot be displayed.
The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).
If a browser cannot find an image, it will display the alt text:
The alt attribute is required. A web page will not validate correctly without it.
A screen reader is a software programs that can read what is displayed on a screen.
Screen readers are useful to people who are blind, visually impaired, or learning disabled.
|Screen readers can read the alt attribute.|
You can use the style attribute to specify the width and height of an image.
The values are specified in pixels (use px after the value):
Alternatively, you can use width and height attributes. Here, the values are specified in pixels by default:
Both the width, height, and style attributes are valid in the latest HTML5 standard.
We suggest you use the style attribute. It prevents styles sheets from changing the original size of images:
If not specified, the browser expects to find the image in the same folder as the web page.
However, it is common to store images in a sub-folder. You must then include the folder name in the src attribute:
Some web sites store their images on image servers.
Actually, you can access images from any web address in the world:
The GIF standard allows animated images:
Note that the syntax of inserting animated images is no different from non-animated images.
To use an image as a link, simply nest the <img> tag inside the <a> tag:
|Add "border:0;" to prevent IE9 (and earlier) from displaying a border around the image.|
Use the CSS float property to let the image float.
The image can float to the right or to the left of a text:
Use the <map> tag to define an image-map. An image-map is an image with clickable areas.
The name attribute of the <map> tag is associated with the <img>'s usemap attribute and creates a relationship between the image and the map.
The <map> tag contains a number of <area> tags, that defines the clickable areas in the image-map:
|Loading images takes time. Large images can slow down your page. Use images carefully.|
|<img>||Defines an image|
|<map>||Defines an image-map|
|<area>||Defines a clickable area inside an image-map|