HTML Image Tag | HTML Tutorial in Hindi / Urdu | Complete HTML Course
HTML Image Tag | HTML Tutorial in Hindi / Urdu | Complete HTML Course
HTML Image Tag
The HTML Image Tag (<img>) is used to display images on a web page. Images play an important role in improving the visual appearance, user engagement, and overall user experience of a website. The <img> element allows developers to add photographs, illustrations, icons, logos, and other visual content to their webpages.
The image tag is an empty element, which means it does not require a closing tag. Instead, it uses attributes to define the image source and its behavior.
The most important attributes of the HTML image tag include:
src Attribute
The src (source) attribute specifies the path or URL of the image that should be displayed on the webpage. Without the src attribute, the browser cannot load the image.
alt Attribute
The alt (alternative text) attribute provides a textual description of the image. This text is displayed if the image cannot be loaded and is also used by screen readers to improve accessibility. Proper use of the alt attribute can also contribute to better SEO performance.
width Attribute
The width attribute defines the width of the image. It helps control how much horizontal space the image occupies on the webpage.
height Attribute
The height attribute defines the height of the image. It allows developers to control the vertical size of the image.
title Attribute
The title attribute displays additional information about the image when a user hovers over it with a mouse pointer.
Best Practices for Using Images in HTML
-
Always use descriptive alternative text with the
altattribute. -
Optimize image file sizes to improve website performance.
-
Use appropriate image formats such as JPG, PNG, SVG, or WebP.
-
Define image dimensions when possible to reduce layout shifts.
-
Keep image file names meaningful and SEO-friendly.
-
Use responsive images to ensure compatibility across different devices and screen sizes.
In this lesson, you will learn how to add images to a webpage, use essential image attributes, and follow best practices for creating modern, accessible, and user-friendly websites using HTML.
<div>
<div><!doctype html></div>
<br>
<div><!-- TheProviders ----------------- youtube.com/@TheProvidersOfficial --></div>
<br><br>
<div><html lang="en"></div>
<div> <head></div>
<div> <meta charset="UTF-8" /></div>
<div> <meta name="viewport" content="width=device-width, initial-scale=1.0" /></div>
<div> <title>Document</title></div>
<div> </head></div>
<div> <body></div>
<div> </div>
<div> <!-- image in same directory --></div>
<div> <img src="image1.jpg" alt=""></div>
<br>
<div> <!-- image in images folder --></div>
<div> <img src="images/image2.jpeg" alt=""></div>
<br>
<div> <!-- Absolute Path and use link to link image --></div>
<div> <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTng1SD0h2twUzTLLlPJT75IhJ-nWL4HJAcCA&s" width="300" height="300" border="5" alt="My Image"></div>
<br><br><br><br>
<div> <br></div>
<div> </div>
<div> <a href="https://youtube.com/@theProvidersOfficial">The Providers</a></div>
<br><br>
<div></body></div>
<div></html></div>
</div>
