What is an HTML image?

In HTML, you can add images in a webpage using the <img> tag. The <img> is an empty tag which means it does not have a closing tag. This tag requires some set of attributes to specify the size, alignment, and other properties of an image.

Attributes

Attributes are properties that you want to set for an element. Some of the commonly used attributes for <img> element are mentioned below:

  • src : short for “source”, this attribute specifies the path where the source (image) is located
  • alt : short for “alternate”, this optional attribute is used to specify alternate text in case the image does not appear
  • width : specifies the width of the image
  • height : specifies the height of the image
  • align : specifies the alignment of the image. Possible values could be left, right, center etc. By default, it is set as left.

Syntax

Here’s the syntax to embed an image in an HTML web page:

<img src = "Image_URL/PATH">
HTML <img> tag
HTML <img> tag

Example

Here’s an example that inserts an image at the right with width and height equal to 150px.

Copyright ©2024 Educative, Inc. All rights reserved