HTML image
Example
Norwegian Mountain Trip
Try it »
Online example
Inserting an image
This example demonstrates how to display images in a web page.
Insert images from different locations
This example demonstrates how to display images from other folders or servers on a web page.
(More examples can be found at the bottom of this page.)
HTML Images - The Image Tag (
) and the Source Attribute (Src)
In HTML, images are defined by the tag.
is an empty tag, meaning it contains only attributes and has no closing tag.
To display an image on a page, you need to use the source attribute (src). src stands for "source". The value of the source attribute is the URL address of the image.
The syntax for defining an image is:
The URL refers to the location where the image is stored. If an image named "pulpit.jpg" is located in the images directory of www.runoob.com, then its URL is http://www.runoob.com/images/pulpit.jpg。
The browser displays the image where the image tag appears in the document. If you place the image tag between two paragraphs, the browser will display the first paragraph, then the image, and finally the second paragraph.
HTML Images - The alt Attribute
The alt attribute is used to define a string of alternative text for an image.
The value of the alternative text attribute is defined by the user.
When the browser cannot load the image, the alternative text attribute tells readers the information they have lost. At this point, the browser will display this alternative text instead of the image. It is a good habit to add alternative text attributes to all images on a page, as it helps display information better and is very useful for those using text-only browsers.
HTML Images - Setting the Height and Width of an Image
The height and width attributes are used to set the height and width of an image.
Attribute values default to pixels:
Tip: It is a good habit to specify the height and width of an image. If the height and width are specified, the page will reserve the specified space when loading. If the image size is not specified, the overall layout of the HTML page may be disrupted when the page loads.
Basic Notes - Useful Tips:
Note: If an HTML file contains ten images, then 11 files need to be loaded to display the page correctly. Loading images takes time, so our advice is: use images carefully.
Note: When loading a page, pay attention to the path of the images inserted into the page. If the image location is not set correctly, the browser cannot load the image and the image tag will display a broken image.
More examples
Arranging images
This example demonstrates how to align images within text.
Floating images
This example demonstrates how to float an image to the left or right of a paragraph.
Setting an Image Link
This example demonstrates how to use an image as a link.
Creating an image map
This example shows how to create an image map with clickable areas. Each of these areas is a hyperlink.
HTML Image Tags
| tag | Description |
|---|---|
| Defines an image | |
| Defines an image map | |
| Defines a clickable area in an image map |