How to Use IMG Tag in HTML with Example A Complete Guide

Logan Jul 13, 2026

The tag is a crucial element in HTML used to embed images into web pages. It's an essential tool for enhancing the visual appeal of your website, making it more engaging and informative. This article will guide you through using the tag in HTML and provide examples to illustrate its application.

Harnessing the Power of the <img> Tag in HTML
Harnessing the Power of the <img> Tag in HTML

Before diving into the details, ensure you have a basic understanding of how HTML tags work. In an HTML document, tags are enclosed in angle brackets <>. You typically insert the content or attributes of a tag between the opening and closing tags.

Embedding Images in HTML using <img>
Embedding Images in HTML using <img>

Basic Structure of the Tag

The tag has a simple structure. The basic syntax is:

What are HTML Tags? List of common HTML Tags
What are HTML Tags? List of common HTML Tags

<img src="URL" alt="alternative text">

The 'src' attribute is mandatory and specifies the URL of the image you want to display. The 'alt' attribute is also crucial as it provides alternative text for browsers that cannot display images, improving accessibility.

Here's a simple example:

HTML TAG
HTML TAG

<img src="https://example.com/image.jpg" alt="A descriptive text about the image">

Specifying Image Size

By default, images maintain their original dimensions. However, you can control the size of the image in your HTML using the 'width' and 'height' attributes. For instance:

<img src="https://example.com/image.jpg" alt="A descriptive text" width="200" height="200">

In this case, the image will be displayed at 200 pixels in both width and height.

the ultimate guide to creating and formating tags
the ultimate guide to creating and formating tags

Image Alignment and Space

To control the placement of an image, you can use the 'align' attribute or CSS. However, 'align' is deprecated, so it's recommended to use CSS for modern web development. Here's how you can use 'align':

<img src="https://example.com/image.jpg" alt="A descriptive text" align="right">

The 'align' attribute can take values like 'left', 'right', 'top', 'middle', 'bottom', or 'absmiddle'. For creating space around an image, you can use HTML line breaks (`
`) or set margins with CSS.

π™ƒπ™π™ˆπ™‡ π™π™–π™œπ™¨ π™˜π™π™šπ™–π™© π™¨π™π™šπ™šπ™©
π™ƒπ™π™ˆπ™‡ π™π™–π™œπ™¨ π™˜π™π™šπ™–π™© π™¨π™π™šπ™šπ™©

Using the
and
Tags for Images

The

tag defines self-contained content, like illustrations, diagrams, photos, code listings, etc. It should be used with the
tag to provide a caption for the
content.

Quick HTML Tags Cheat Sheet
Quick HTML Tags Cheat Sheet
Commonly Used HTML Tags with Examples - DataFlair
Commonly Used HTML Tags with Examples - DataFlair
🏷️ HTML Tags Cheat Sheet | Essential Tags Every Beginner Should Know
🏷️ HTML Tags Cheat Sheet | Essential Tags Every Beginner Should Know
About HTML tags
About HTML tags
10 Essential HTML Tags Every Developer Should Know"
10 Essential HTML Tags Every Developer Should Know"
10 Basic HTML Tags for Bloggers: One Stop Shopping!
10 Basic HTML Tags for Bloggers: One Stop Shopping!
HTML Tags β€” List of all HTML Tags with Examples TutorialBrain
HTML Tags β€” List of all HTML Tags with Examples TutorialBrain
the 5 must know html tags for beginners infographical image below is an example of how to use them
the 5 must know html tags for beginners infographical image below is an example of how to use them
887 reactions · 135 shares | HTML5 Tags information 2026. #coding #webdevelopment✨ #htmlcssjavascript #programming | Premi Coding | Facebook
887 reactions · 135 shares | HTML5 Tags information 2026. #coding #webdevelopment✨ #htmlcssjavascript #programming | Premi Coding | Facebook
HTML Heading Tag Example
HTML Heading Tag Example
Title: HTML Semantic vs Non-Semantic Tags – Guide by RajNandani
Title: HTML Semantic vs Non-Semantic Tags – Guide by RajNandani
Saidul (@saidul_dev) on X
Saidul (@saidul_dev) on X
HTML TAGS | PART 1
HTML TAGS | PART 1
HTML tags are arranged in the following manner
HTML tags are arranged in the following manner
Types of tags in HTML
Types of tags in HTML
HTML Full Form + 10 Essential Tags Every Beginner Must Know πŸš€
HTML Full Form + 10 Essential Tags Every Beginner Must Know πŸš€
the basic html tag list is displayed in this screenshote screen graber, which shows
the basic html tag list is displayed in this screenshote screen graber, which shows
7 Best HTML Tags for Improving Your Website's SEO
7 Best HTML Tags for Improving Your Website's SEO
HTML TAGS
HTML TAGS
πŸ”₯ HTML Heading Tags Explained (H1 to H6) with Examples | Complete HTML Tutorial for Beginners
πŸ”₯ HTML Heading Tags Explained (H1 to H6) with Examples | Complete HTML Tutorial for Beginners

Here's an example:

<figure> <img src="https://example.com/image.jpg" alt="A descriptive text"> <figcaption>This is a caption for the image.</figcaption> </figure>

Responsive Images with the Tag

The tag allows you to specify multiple image sources to cater to different display densities and sizes, making it perfect for responsive design. Here's an example:

<picture> <source srcset="large.jpg 1920w, medium.jpg 1024w, small.jpg 640w"> <img src="small.jpg" alt="A descriptive text"> </picture>

In this case, the browser will select the most appropriate source based on the user's screen size and resolution.

Optimizing Images for the Web

Always strive to optimize your images for the web to ensure fast loading times. This can be achieved by reducing the file size without losing quality and by compressing images.

The final paragraph is often tricky, but here's a natural way to wrap up this discussion. Remember, the world of HTML images is vast, and we've only scratched the surface. There's always more to explore, like using JavaScript for image manipulation or CSS for styling images. So, keep learning, and happy coding!