Home >>HTML Tutorial >HTML Images

HTML Images

HTML Images

HTML provides you <img> tag to add images to your webpages. Only using texts in website, it made them appear quite boring and uninteresting. So, <img> tag is used to add images in webpages. It helps you to improve the designs and appearance of web pages.

<img> tag is also known as empty tag because there is no closing tags. It contains attributes only.

Attributes of HTML <img> tags are:

  1. Src- It is necessary attribute, it describes the path/source of the image. It instructs the browser where to look for the image to display in webpages. May be the image location is on same folder or another server.
  2. Alt- It describes the alternate text for the image. If image can’t be displayed, the value of alt attributed describe the image in text.
  3. Width- You can use width attributes to set the width of the image. But now you can set width by using CSS.
  4. Height- Height attribute is used to set the height of the images, if you want. In this, you can use CSS to set the height of the image.

Let's take an example:

<!DOCTYPE html> 
<html> 
<head> 
	<title>Inserting an image</title> 
</head> 
<body> 
	<img src= "https://cdn140.picsart.com/315857494228201.jpg?type=webp&to=crop&r=256&q=70"
		alt="Img"> 
</body> 
</html>
Output:
Img

Setting Height and width of the image: The attributes height and width value are specified in pixels by default.

Let's take an example of setting the height and width of the image:

<!DOCTYPE html> 
<html> 
<head> 
	<title>Inserting an image</title> 
</head> 
<body> 
	<img src= "https://cdn140.picsart.com/315857494228201.jpg?type=webp&to=crop&r=256&q=70"
		alt="Img" height="300" width="300"> 
</body> 
</html> 
Output:
Img

Adding animated Images: you can also add animated image in webpages. But it is necessary to use the extension of the image .gif.

Let's take an example of adding animated images:

<!DOCTYPE html> 
<html> 
<head> 
	<title>Inserting an image</title> 
</head> 
<body> 
<img src="1.gif" 
	alt="phptpoint.gif" height="300" width="300"> 
</body> 
</html>
Output:
phptpoint.gif

No Sidebar ads