Write an HTML program to display an image

Description: Create a web page that shows an image of size 120 x 80 pixels, and another copy of the image that opens a website when clicked.

Hint:

  • Use the <img> tag with src, alt, width and height.
  • Put the image inside an <a> tag to make it a link.

HTML program to display an image

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Image</title>
</head>
<body>
  <img src="orange.png" alt="Orange sample picture" width="120" height="80">

  <a href="https://www.example.com">
    <img src="orange.png" alt="Go to Example" width="120" height="80">
  </a>
</body>
</html>

Output in the browser:

Output in the browser

How it works

  • src is the path of the picture. Keep the file in the same folder as the HTML file, or write the right path.
  • alt is shown if the picture cannot load.
  • Inside <a> the image becomes clickable.

Read HTML Images.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.