<img src="pic_trulli.jpg" alt="Italian Trulli">
<img src="img_girl.jpg" alt="Girl in a jacket">
<img src="img_chania.jpg" alt="Flowers in Chania">
In HTML, images are defined with the
<img> tag is empty, it contains attributes only, and does not have a closing tag.
src attribute specifies the URL (web address) of the image:
alt attribute provides an alternate text for an image, if the 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).
The value of the
alt attribute should describe the image:
If a browser cannot find an image, it will display the value of the
You can use the
style attribute to specify the width and height of an image.
Alternatively, you can use the
height attributes always defines the width and height of the image in pixels.
Note: Always specify the width and height of an image. If width and height are not specified, the page might flicker while the image loads.
style attributes are valid in HTML5.
However, we suggest using the
style attribute. It prevents styles sheets from changing the 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
Some web sites store their images on image servers.
Actually, you can access images from any web address in the world:
HTML allows animated GIFs:
To use an image as a link, put the
<img> tag inside the
border:0; is added to prevent IE9 (and earlier) from displaying a border around the image (when the image is a link).
Use the CSS
float property to let the image float to the right or to the left of a text:
<map> tag defines an image-map. An image-map is an image with clickable areas.
In the image below, click on the computer, the phone, or the cup of coffee:
name attribute of the
<map> tag is associated with the
<img>'s usemap attribute and creates a relationship between the image and the map.
<map> element contains a number of
<area> tags, that define the clickable areas in the image-map.
To add a background image on an HTML element, use the CSS property
To add a background image on a web page, specify the background-image property on the BODY element:
To add a background image on a paragraph, specify the background-image property on the P element:
HTML5 introduced the
<picture> element to add more flexibility when specifying image resources.
<picture> element contains a number of <source> elements, each referring to different image sources. This way the browser can choose the image that best fits the current view and/or device.
<source> element have attributes describing when their image is the most suitable.
The browser will use the first
<source> element with matching attribute values, and ignore any following
Show one picture if the browser window (viewport) is a minimum of 650 pixels, and another image if not, but larger than 465 pixels.
Note: Always specify an
<img> element as the last child element of the
<picture> element. The
<img>element is used by browsers that do not support the
<picture> element, or if none of the
<source> tags matched.
A screen reader is a software program that reads the HTML code, converts the text, and allows the user to "listen" to the content. Screen readers are useful for people who are visually impaired or learning disabled.
<img>element to define an image
srcattribute to define the URL of the image
altattribute to define an alternate text for an image, if it cannot be displayed
heightattributes to define the size of the image
heightproperties to define the size of the image (alternatively)
floatproperty to let the image float
<map>element to define an image-map
<area>element to define the clickable areas in the image-map
usemapattribute to point to an image-map
<picture>element to show different images for different devices
Required fields are marked *
Get all latest content delivered to your email free.