What is HTML Image <img> tag?
HTML <img> tag is used to display image on the web page.
Inserting images in the webpage improves the design and the appearance of a web page.
What are the attributes used for image tag?
There are four attributes used for image tag, listed below
1. src
2. alt
3. width
4. height
1. src
src attribute describes the source or path of the image.
This instructs the browser where to look for the image on the server.
2. alt
alt attribute defines an alternate text for the image.
alt attribute “value” describes the image in words.
alt attribute “value” is mainly used in SEO prospective, which will be discussed later.
alt attribute is optional param.
3. width
width attribute is used to specify the width to display the image.
width attribute is optional param.
4. height
height attribute is used to specify the height to display the image.
Usually this takes the height of <h3> as default.
HTML beginners tutorial !!!
Click to Learn More about – HTML Tutorial for beginners
How to insert an image in webpage ?
There are three ways to insert image in webpage, listed below
1. Insert image directly from the same folder.
2. Insert image from any of the sub-folder.
3. Insert image from server or website.
1. Simple image insert with src attribute
Example :
<!DOCTYPE html>
<html>
<head>
<title>Image tag</title>
</head>
<body>
<img src="html-icon-copyright-img-frontpage.png">
</body>
</html>
Output :

2. Insert image with other attributes / Insert image directly from the same folder.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Image tag</title>
</head>
<body>
<img src="html-icon-copyright-img-frontpage.png" alt="HTML Topics Tutorials" width="200px" height="400px">
</body>
</html>
Output :

3. Insert image from any of the sub-folder.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Image tag</title>
</head>
<body>
<img src="../images/html-icon-copyright-img-frontpage.png" alt="HTML Topics Tutorials" width="200px" height="400px">
</body>
</html>
Output :

4. Insert image from server or website.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Image tag</title>
</head>
<body>
<img src="https://secureservercdn.net/192.169.221.188/s30.e0b.myftpupload.com/wp-content/uploads/2020/06/core-java-copyright-img-1.png" alt="Core Java Topics Tutorials" width="200px" height="400px">
</body>
</html>
Output :

<img> Tag Attributes
HTML <img> tag support following specific attributes.
Sno | Attributes | Value | Description |
---|---|---|---|
1 | alt | text | Specify an alternate text of an image. |
2 | crossorigin | anonymous use-credentials | This attribute allow to load images from an Cross-0rigin access (Other sites). |
3 | height | pixels | Specify the height of an image. |
4 | ismap | ismap | Specify an image as a server side image map. |
5 | longdesc | URL | Specify an URL that contains details description of an image. |
6 | src | URL | Specify an URL of an image. |
7 | usemap | #idname | Specify an image as a client-side image-map. |
8 | width | pixels | Specify the width of an image. |
9 | Following attributes has been removed in HTML5. | ||
10 | align | left right top middle bottom | Specify the alignment of an image according to parent element. |
11 | border | pixels | Specify the width of the border. Border display around an image. |
12 | hspace | pixels | Specify the whitespace that added on left and right side of an image. |
13 | vspace | pixels | Specify the whitespace that added on top and bottom of an image. |
Global Attributes
HTML <img> tag support following global attributes.
Sno | Attributes | Value | Description |
---|---|---|---|
1 | id | unique_name | Declared unique id for an element. |
2 | class | class_name | Declared one or more classnames for an element. |
3 | style | styles | CSS inline styles specify an element. |
4 | title | title | Specify extra details of element contain, this will display as a “tooltip” for an elements. |
Event Attributes
HTML <img> tag support following event attributes.
Sno | Attributes | Value | Description |
---|---|---|---|
1 | onfocus | script | element gets focus on object when script tobe run. |
2 | onblur | script | element lose the focus on object when scrip tobe run. |
3 | onabort | script | element gets aborted on object when script tobe run. |
4 | onchange | script | element gets anytime change on object when script tobe run. |
5 | onbeforeunload | script | element gets unloaded on object when scrip tobe run. |
6 | onclick | script | clicked on object when script tobe run. |
7 | ondblclick | script | double click on object when script tobe run. |
8 | onkeydown | script | key is pressed when script tobe run. |
9 | onkeypress | script | key is pressed over element then released when script tobe run. |
10 | onkeyup | script | key is released over element when script tobe run. |
11 | onmousedown | script | mouse button was pressed over an element when script tobe run. |
12 | onmouseout | script | mouse pointer release over an element when script tobe run. |
13 | onmousemove | script | run mouse pointer moved when script tobe run. |
14 | onmouseover | script | run mouse pointer move over when script tobe run. |
15 | onmouseup | script | mouse button is released when script tobe run. |
16 | onreset | script | form has been reset when script tobe run. |
17 | onselect | script | Select some content when script tobe run. |
18 | onsubmit | script | form has been submitted when script tobe run. |
19 | onload | script | object has load when script tobe run. |
20 | onchange | script | allow to change the object when script tobe run. |
21 | onunload | script | unload to the browser window when script tobe run. |
22 | ondrag | script | element being dragged when script tobe run. |
23 | ondragend | script | element being stop dragged when script tobe run. |
24 | ondragenter | script | element being go target dragged when script tobe run. |
25 | ondragleave | script | element being leave to target dragged when script tobe run. |
26 | ondragover | script | element being over to target dragged when script tobe run. |
27 | ondragstart | script | element being start dragged when script tobe run. |
28 | ondrop | script | element being dropped when script tobe run. |
29 | onerror | script | element error occurs when script tobe run. |
30 | onmessage | script | element message display when script tobe run. |
31 | onerror | script | element error occurs when script tobe run. |
32 | onmousewheel | script | mouse wheel will be rotate when script tobe run. |
33 | onscroll | script | scrollbar is scroll when script tobe run. |
34 | onresize | script | element should be resize when script tobe run. |
35 | onselect | script | all element content selected when script tobe run. |
36 | onstorage | script | element should be store in target when script tobe run. |
Browser Compatibility
Sno | Browser | Support |
1 | Chrome | Yes |
2 | Firefox | Yes |
3 | Edge | Yes |
4 | Opera | Yes |
5 | Safari | Yes |
6 | Internet Explorer | Yes |