HTML Images

  • The <img> tag is empty

Note: The empty tags do not have a closing tag.

  • The src attribute is used for the URL (web address) of the image.
  • The alt attribute is used for alternate text for an image.

Note: if the users for any reason cannot view the image then this attribute is used to show the details about the image. (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

Example of HTML Image Tag
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<img src="republic-day.jpg" alt="republic-day">
</body>
</html>

HTML Image Width and Height

  • The width and height attributes is used to set the Image width and height.
Example of HTML Image width and height
<!DOCTYPE html>
<html>
<head>
<title>HTML IMAGE TAG</title>
</head>
<body>
<h4> HTML Images</h4>
<img src="republic-day.jpg" height="180" width="300" alt="republic-day"/>
</body>
</html>