Introduction:

In this article we are going to explain what is img tag in html or how to add an image on web page using img tag with example.

Description:

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.

Syntax:

<img src="url" alt="some_text">

Example:

<img src="good_morning.jpg" alt="Good Morning Friends"/>  


Let's see an example of HTML image.

 <!DOCTYPE html>
<html>
<head>
    <title>Example of image tag </title>   
</head>
<body>
    <img src="good_morning.jpg" alt="Good Morning Friends" /> 
  
</body>
</html>

Output:

 how to use image tag in html

Attributes of HTML img tag

The src and alt are important attributes of HTML img tag. All attributes of HTML image tag are given below.

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.


alt: The alt attribute defines an alternate text for the image, if it can't be displayed. The value of the alt attribute describe the image in words.  


width: It is an optional attribute which is used to specify the width to display the image.


height: It specifies the height of the image.


border : the border  attribute to add border to the image

align: the align attribute to set image alignment.


I hope this article will help to you after reading.

 Let's check live example

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like