Skip to main content

<img> - Image

The image element is an element for displaying an image in a web page. It can be defined by using a single <img /> tag.

To display an image in the page, you need to provide a value to src attribute in the tag. There are also other attributes you can define in the tag to customise how the image is displayed. The attributes are explained in Possible Attributes.

Possible Attributes

  • src: The address (i.e. URL) pointing to the location where the image is stored.
  • alt: Textual description of the image that will be read by screen reader commonly used by visual-impaired people. It is also used as stand-in value that will be displayed by the browser if the image cannot be loaded.
  • height: Set the height of the image.
  • width: Set the width of the image.

Note: As you progress in learning about Web design, you will notice that you can set the dimension of an image using HTML attribute and CSS. The recommended approach in defining the dimension, and the style of an image in general, is to use CSS. The main purpose of HTML is to define a structure to a web page, while CSS' is to tell browser how to display the elements in the page.

Usage Example

Loading Code Editor...

Output: