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
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>
Basic Structure of the Tag
The tag has a simple structure. The basic syntax is:
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
<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:
In this case, the image will be displayed at 200 pixels in both width and height.
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':
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.
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 SheetCommonly Used HTML Tags with Examples - DataFlairπ·οΈ HTML Tags Cheat Sheet | Essential Tags Every Beginner Should KnowAbout HTML tags10 Essential HTML Tags Every Developer Should Know"10 Basic HTML Tags for Bloggers: One Stop Shopping!HTML Tags β List of all HTML Tags with Examples TutorialBrainthe 5 must know html tags for beginners infographical image below is an example of how to use them887 reactions Β· 135 shares | HTML5 Tags information 2026. #coding #webdevelopmentβ¨ #htmlcssjavascript #programming | Premi Coding | FacebookHTML Heading Tag ExampleTitle: HTML Semantic vs Non-Semantic Tags β Guide by RajNandaniSaidul (@saidul_dev) on XHTML TAGS | PART 1HTML tags are arranged in the following mannerTypes of tags in HTMLHTML Full Form + 10 Essential Tags Every Beginner Must Know πthe basic html tag list is displayed in this screenshote screen graber, which shows7 Best HTML Tags for Improving Your Website's SEOHTML TAGSπ₯ 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:
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!