Begin Web Programming with PHP & MySQL

Advertisements



Inserting Images

  • The <img> tag is used to embed an image in an HTML page.
  • Images are not technically inserted into a web page; images are linked to web pages.
  • The <img> tag creates a holding space for the referenced image.
  • The <img> tag is empty, it contains attributes only, and does not have a closing tag.
  • The <img> tag has two required attributes:
    • src - Specifies the path to the image
    • alt - Specifies an alternate text for the image
  • Eg: <img src="indian_flag.jpg" alt="Indian Flag" width="300" height="200"> The width and height attributes always define the width and height of the image in pixels.
    Output:
    Indian Flag

Attributes

The <img> tag has some important attributes:

Attribute Description
src It is used to specify the path to the image.
alt It is used to specify an alternate text for the image. It is useful as it informs the user about what the image means and also due to any network issue if the image cannot be displayed then this alternate text will be displayed.
crossorigin It is used to import images from third-party sites that allow cross-origin access to be used with canvas.
height It is used to specify the height of the image
width It is used to specify the width of the image.
loading It is used to specify whether a browser should defer loading of images until some conditions are met or load an image immediately.