HTML Image
HTML Image
HTML Image
HTML img tag is used to display image on the web page. HTML img tag is an empty tag
that contains attributes only, closing tags are not used in HTML image element.
Output:
1) src
It is a necessary attribute that describes the source or path of the
image. It instructs the browser where to look for the image on the
server.
The location of image may be on the same directory or another
server.
2) alt
The alt attribute defines an alternate text for the image, if it can't be
displayed.
3) width
It is an optional attribute which is used to specify the width to
display the image.
4) height
It is used to specify the height of the image.
The HTML height attribute also supports iframe, image and object
elements.
Example:
1. <img src="animal.jpg" height="180" width="300" alt="animal ima
ge">
Output:
Note: Always try to insert the image with height and width, else it may flicker while
displaying on webpage.
Output:
How to get image from another directory/folder?
To insert an image in your web, that image must be present in your same
folder where you have put the HTML file. But if in some case image is
available in some other directory then you can access the image like this:
Note: If src URL will be incorrect or misspell then it will not display your image on web
page, so try to put correct URL.
Example:
1. <a href="https://www.javatpoint.com/what-is-robotics"><img sr
c="robot.jpg" height="100" width="100"></a>