"Learn to Insert Images in HTML: A Step-by-Step Guide"

Roger Jun 10, 2026

Embedding Images in HTML: A Comprehensive Guide

Inserting and styling images in HTML 5.
Inserting and styling images in HTML 5.

In the digital landscape, images are as essential as text. They engage users, break up content, and often convey information more effectively than words alone. This guide will walk you through the process of incorporating images into your HTML documents, ensuring your webpages are both visually appealing and informative.

Basic HTML Images
Basic HTML Images

Understanding the HTML Image Tag

The HTML <img> tag is used to embed images in webpages. It's an empty tag, meaning it doesn't have a closing tag like </img>. Here's the basic syntax:

an image with the text how to place text over image in html css
an image with the text how to place text over image in html css

<img src="URL" alt="Alternative Text">

src Attribute

The 'src' attribute specifies the URL of the image. This can be a local file path, a URL to an image hosted elsewhere, or a data URL for inline images.

4 Ways To Keep Image Aspect Ratio In HTML CSS
4 Ways To Keep Image Aspect Ratio In HTML CSS

alt Attribute

The 'alt' attribute provides alternative text for an image, improving accessibility for visually impaired users and search engine optimization. It's a best practice to always include an 'alt' attribute.

Inserting an Image

Create Rounded Images In HTML CSS
Create Rounded Images In HTML CSS

Local Image

To insert an image stored on your local machine or server, use the following syntax:

<img src="path/to/your/image.jpg" alt="Description of the image">

Image from the Web

CSS image slider
CSS image slider

To use an image hosted on the web, replace 'path/to/your/image.jpg' with the image's URL:

<img src="https://example.com/image.jpg" alt="Description of the image">

Image Size and Alignment

Create Image Accordion Slider With HTML CSS And JavaScript
Create Image Accordion Slider With HTML CSS And JavaScript
a computer screen with the text html and an image of a web page on it
a computer screen with the text html and an image of a web page on it
an image of a blue screen with the words html structure in white letters on it
an image of a blue screen with the words html structure in white letters on it
Auto Resize Images In HTML CSS
Auto Resize Images In HTML CSS
Image Hover Animation in HTML & CSS
Image Hover Animation in HTML & CSS
the three ways to apply css in html and wordpress, including an info sheet
the three ways to apply css in html and wordpress, including an info sheet
How to Set a Background Image in CSS
How to Set a Background Image in CSS
How to create a Amazing Image Gallery using HTML CSS only
How to create a Amazing Image Gallery using HTML CSS only
#CSS Animations Tips and Tricks
#CSS Animations Tips and Tricks
Build Animated Website Using HTML CSS and JavaScript
Build Animated Website Using HTML CSS and JavaScript
an image with the text, click box for more information and then clickbox for more information
an image with the text, click box for more information and then clickbox for more information
Animation Login Form | Html&Css.
Animation Login Form | Html&Css.
Simple Image Slider In HTML CSS
Simple Image Slider In HTML CSS
an image of a web page with the text'html inputt types '
an image of a web page with the text'html inputt types '
32 HTML And CSS Projects For Beginners (With Source Code)
32 HTML And CSS Projects For Beginners (With Source Code)
Transparent Text Background Image In HTML CSS
Transparent Text Background Image In HTML CSS
Simple Blinking Effect In HTML CSS
Simple Blinking Effect In HTML CSS
Coding a Stylish Blog Design Layout in HTML & CSS
Coding a Stylish Blog Design Layout in HTML & CSS
Simple Responsive Image Gallery In HTML CSS
Simple Responsive Image Gallery In HTML CSS
an image of a web page with the words in different languages and numbers on it
an image of a web page with the words in different languages and numbers on it

By default, images will retain their original size. However, you can control their size and alignment using CSS. Here's how you can do it:

Setting Image Size

You can set the width and height of an image using the 'width' and 'height' attributes:

<img src="image.jpg" alt="Description" width="300" height="200">

Aligning Images

Use the 'align' attribute to left, right, or center align an image. However, note that this attribute is deprecated in HTML5. It's recommended to use CSS for alignment instead.

<img src="image.jpg" alt="Description" align="left">

Responsive Images

To make your images responsive and adapt to different screen sizes, you can use the 'srcset' attribute and provide multiple image sources:

<img srcset="small.jpg 480w, medium.jpg 800w, large.jpg 1080w" alt="Description">

Conclusion

Incorporating images into your HTML documents is a straightforward process. By understanding the <img> tag and its attributes, you can enhance your webpages with engaging visuals. Always remember to include alternative text for accessibility and SEO purposes.