"Insert Image in HTML: A Step-by-Step Guide with Examples"

Christopher Jun 16, 2026

Inserting Images in HTML: A Step-by-Step Guide

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

Inserting images into your HTML document can be a simple process if you know the right tags and attributes. In this guide, we will walk you through the steps of adding images to your HTML pages, including understanding the basic tags and attributes, setting image dimensions, and providing alt text for accessibility.

How to Insert an Image in HTML Page?
How to Insert an Image in HTML Page?

The Basic Syntax

The basic syntax for inserting an image in HTML involves using the tag. This tag requires two main attributes: src (source) and alt (alternative text). The src attribute specifies the path to the image file, while the alt attribute provides a text description of the image for users who cannot see it.

Auto Resize Images In HTML CSS
Auto Resize Images In HTML CSS

Here's a simple example of how to insert an image:

However, this is a static image, and you might want to add more functionality to it, such as resizing or adding a link. We'll discuss these advanced features later.

3 Ways To Place Text Over Image In HTML CSS
3 Ways To Place Text Over Image In HTML CSS

Setting Image Dimensions

By default, an image will occupy the full width of its parent element. However, you can control its size by adding the width and height attributes to the tag.

For example, to set an image width to 500 pixels, you can use the following code:

an image of a computer screen with some pictures on it and the text, color fuel
an image of a computer screen with some pictures on it and the text, color fuel

Remember, these attributes are in pixels and can be replaced with percentages for relative sizes.

Providing Alt Text

Alt text is crucial for accessibility and search engine optimization (SEO). It describes the content of the image to users who cannot see it, such as screen readers. Make sure to keep the alt text descriptive but concise.

How To Create Image Gallery In HTML, CSS and Javascript | Lightbox Gallery
How To Create Image Gallery In HTML, CSS and Javascript | Lightbox Gallery

A good practice is to include the keyword you're targeting in your image alt text. For example, if your image is of a "red car," your alt text could be "A red car parked on the road."

Adding Links to Images

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
Very Simple HTML CSS Image Gallery
Very Simple HTML CSS Image Gallery
How to use the HTML5 elements - jensjaeger.com
How to use the HTML5 elements - jensjaeger.com
Position Text Over Image In HTML CSS (Simple Examples)
Position Text Over Image In HTML CSS (Simple Examples)
Input types in HTML
Input types in HTML
html and css login form
html and css login form
an image slider is shown with multiple images on the screen and text below it
an image slider is shown with multiple images on the screen and text below it
Create Image Accordion Slider With HTML CSS And JavaScript
Create Image Accordion Slider With HTML CSS And JavaScript
a table with several different types of text and numbers on the top, bottom left corner
a table with several different types of text and numbers on the top, bottom left corner
How to Set a Background Image in CSS
How to Set a Background Image in CSS
an image of a computer screen with some lines on the bottom and one line in the middle
an image of a computer screen with some lines on the bottom and one line in the middle
How to Insert a Photo into Text in Photoshop
How to Insert a Photo into Text in Photoshop
4 Ways To Keep Image Aspect Ratio In HTML CSS
4 Ways To Keep Image Aspect Ratio In HTML CSS
Creative Image Hover Effects with HTML & CSS
Creative Image Hover Effects with HTML & CSS
Add Watermark With HTML & CSS
Add Watermark With HTML & CSS
the four ways to add css in your web page or email address info sheet
the four ways to add css in your web page or email address info sheet
Pet Pet Generator
Pet Pet Generator
Saidul (@saidul_dev) on X
Saidul (@saidul_dev) on X
Transparent Background Image In HTML CSS
Transparent Background Image In HTML CSS
Upload Image using JS 🤳| HTML CSS JavaScript
Upload Image using JS 🤳| HTML CSS JavaScript

You can turn an image into a link by adding the href attribute to the tag. This attribute specifies the link destination. Here's an example:

When clicked, the image will redirect the user to the specified URL.

Resizing and Scaling Images

You can also resize and scale images using CSS. This method is more flexible than using the width and height attributes in the tag. Here's an example:

  • An image of a beautiful landscape

Replace the width value with the desired size, and you can also use other CSS properties for more complex transformations.

Conclusion (Not really)

We've covered the basics of inserting images into your HTML document, including understanding the tag, setting image dimensions, providing alt text, adding links, and resizing images with CSS. Remember to keep your images descriptive and accessible, and don't hesitate to explore more advanced features like image maps and icon fonts.