What content strategy and technology will leading brands use in 2026?

The state of digital content

How to insert an image in HTML: A simplified guide

by Canto  |  March 31, 2026

15 min. read

At some point, everyone comes across HTML. If you’re unfamiliar with HTML, that’s no problem. You can still easily insert images into a blog post or webpage using it. In fact, it’s not really that difficult if you understand a few basic principles. Here’s a guide to help you out.

Understanding images in HTML

Images are an essential part of web development, and HTML provides a simple way to add them to web pages. Whether you’re showcasing products, sharing photos, or adding visual interest, images can significantly enhance the user experience.

HTML makes it easy to insert images with just a few lines of code, allowing you to create visually appealing web pages without much hassle. You can add images to your web pages using the HTML image tag (<img>), which is essential for displaying meaningful content, while decorative images are better handled with CSS backgrounds.

By understanding the basics of HTML images, you can effectively use them to enrich your web content and engage your audience, and easily add images to your web pages.

It’s important to note that images are technically inserted into a web page by referencing their file locations with the <img> tag, rather than embedding the image data directly in the HTML.

Working with image files

FormatBest forKey benefit
JPEGPhotos, colorful imagesGreat compression for rich color
PNGGraphics with transparency, sharp edgesLossless quality, supports transparency
SVGLogos, iconsScales perfectly on any screen size
WebPGeneral useSuperior compression for faster load times

In HTML, every image you want to show uses the <img> tag, and the src attribute is your guide — it tells the browser exactly where to find your image file.

You can use relative paths (e.g., images/photo.jpg if your image is in the same folder or a subfolder) or absolute URLs (e.g., https://example.com/images/photo.jpg if your image is hosted elsewhere). Get the img src attribute right, and your images will appear just where you want them.

Big image files can slow down your page, so it’s best to compress them before uploading. Tools like TinyPNG or Squoosh help shrink file sizes without losing quality.

Keep your image files organized in a dedicated folder within your website’s directory. This makes managing and referencing them in your HTML code much easier — like having a tidy toolbox.

If your HTML file and image are in the same folder, your <img> tag might look like this: <img src=”my-image.png” alt=”Description of image”>. If your images are in a separate folder, use a path like <img src=”images/my-image.png” alt=”Description of image”>. The alt attribute provides text descriptions of images for screen readers.

Make sure to give your image files clear, descriptive names and keep them in easy-to-find places, especially as your site grows. Paying attention to file types, sizes, and organization helps your images load quickly, look sharp, and work well on all browsers and devices. Managing your content doesn’t have to be hard — we’ll guide you through it.

Tip: Don’t forget accessibility — making your site usable for everyone is important.

How to insert an image with HTML

There are different paths each user can take to complete this step, so don’t be surprised if your route differs from others. The <img> tag requires the ‘src’ and ‘alt’ attributes, which must be included for proper functionality and accessibility.

The src attribute in the <img> tag specifies the location of an image file. Omitting these required attributes, especially the src attribute, can result in broken images or accessibility issues.

It is crucial to specify the correct file path in the img src attribute to ensure that images render properly on a web page, whether using relative or absolute paths.

Path typeWhen to useExample
Relative pathImage is in the same directory or subfolderssrc=”images/photo.jpg”
Absolute URLImage is hosted externallysrc=”https://example.com/images/photo.jpg”

Images can also be hosted on external websites, and you can link to them using an absolute URL in the src attribute.

1. Upload your image

This can be accomplished with an image hosting service, an FTP service, or a blog-hosting service. Select whichever works best for you.

Begin your insertion by uploading an image.

2. Open your HTML document

To start working with images in HTML, you’ll need to open your HTML document in a text editor or IDE. If you’re using a code editor, make sure it’s set to display HTML syntax highlighting. This feature helps you easily identify different parts of your code, making it easier to spot errors and understand the structure of your HTML document.

If you’re using a plain text editor, you can still write HTML code, but you won’t have the benefit of syntax highlighting. Regardless of the tool you choose, ensure that you’re working on the correct HTML document where you want to insert the image.

3. Copy and paste your image URL into an IMG tag, and add a SRC to it

Identify first where you’d like to place your image within the HTML and insert the image tag, < img>**. Then take your uploaded image files, copy the URL, and paste it into the src parameter of your img tag. Images are technically not inserted into the HTML page but are linked via the < img> tag, which creates a placeholder for the referenced image.

The result of this step should look like this:

< img src=”(your image URL here)”>**

The < img> tag is a void element and does not require an end tag.

The ‘alt’ attribute is crucial as it provides alternative text when an image fails to load. The alt attribute is required for the <img> tag and provides alternate text (alt text) for the image, which is important for accessibility and for users with slow connections, where images may not load promptly.

The alternate text helps users with visual impairments and ensures that descriptive information is available when images cannot be displayed. This enhances accessibility for users with slow connections or visual impairments, while also improving search engine indexing and ranking capabilities by providing context around the displayed image.

4. Add alt attribute and finishing touches

The HTML alt attribute is important for accessibility and SEO. It helps users with visual impairment and search engines identify what the picture entails. For example, if it’s a picture of an umbrella on a beach, write the alt tag to include something about a beach umbrella. Be very descriptive, as if you were describing it to someone who couldn’t look at it.

Providing detailed alt text is especially important for users with visual impairment, as it enables them to understand image content through screen readers.

Image dimensions and style

When adding an image to a web page, you can control its dimensions and style using HTML attributes. Specifying the image size with the width and height attributes helps browsers allocate space for the image before it loads, improving page stability. In particular, setting the image’s width attribute allows browsers to reserve the correct horizontal space, helping prevent layout shifts and optimizing page rendering performance.

AttributeWhat it doesExamples
srcPoints to the image file locationsrc=”images/photo.jpg”
altProvides alternative text for accessibilityalt=”Beach umbrella at sunset.”
widthSets horizontal size in pixelswidth=”500″
heightSets vertical size in pixelsheight=”300″
styleApplies inline CSS stylingstyle=”border: 1px solid black”

By using these attributes, you can ensure that your images fit well within your web page layout and have the desired visual appearance.

The style attribute can also be used to set display properties, such as inline-block, which helps control how images and surrounding content are positioned on the page.

Managing surrounding content with CSS, such as using block or inline-block display, helps prevent layout shifts and improve the user experience.

How to put an image into a directory in HTML

If you have a website and you’re trying to insert an image into a directory, the process is relatively straightforward. Here’s how it’s done in three easy steps:

  1. Copy the file path of the image you wish to insert.
  2. Open your index.html file and insert the img code. Example: < img src=”(your image URL here)”>**. Note that the ‘img’ tag does not require a ‘closing tag’.
  3. Save the HTML file. The HTML file has now been created or updated to include the image. The next time you open it, you’ll see the webpage with your newly added image.

How to link an image in HTML

Linking an image in HTML requires a few extra steps, especially if you want to change specific attributes or details. Here’s a complete step-by-step that covers all you’ll need.

To link an image in HTML, follow these steps:

  • Start with the <a> tag, which creates a hyperlink.
  • Add the href attribute to the <a> tag and set it to the URL you want the link to point to.
  • Inside the <a> tag, insert the <img> tag to display the image.
  • Use the src attribute within the <img> tag to specify the image file’s location.
  • Remember that while images are typically linked using the <img> tag, you can also embed other dynamic content, such as videos or maps, using HTML elements like <iframe> to embed external resources directly within your webpage.

The CSS background-image property can also be used to set images as backgrounds for web pages and HTML elements.

This property is better suited for decorative purposes, as it allows for easier control and positioning of images. However, it lacks semantic meaning, making it less suitable for content that requires textual equivalents. Now, to change the attributes, you’ll need to know the following.

First, the title attribute is set to “(your title)”. However, most browsers do not reliably display the title attribute for images, which can affect accessibility and user experience.

HTML is a pretty straightforward language, but it’s okay if you don’t want to learn it in-depth. Just make sure you have the basics down.

Working with background images

Background images add a visual element to a web page without affecting the content. In HTML, you can add a background image using the background-image property in CSS.

Here’s an example: body { background-image: url(‘background.jpg’); background-repeat: no-repeat; background-size: cover; } This code sets the background image to background.jpg and sets the repeat and size properties to ensure the image covers the entire page.

The background-repeat: no-repeat property prevents the image from repeating, and background-size: cover ensures the image covers the entire background area.

You can also use the background shorthand property to set multiple background image properties at once: body { background: url(‘background.jpg’) no-repeat center/cover; } This code sets the background image to background.jpg, sets the repeat property to no-repeat, and sets the size property to cover.

The center value centers the background image horizontally and vertically. Using background images effectively can enhance the visual appeal of your web page without interfering with the main content.

Best practices for adding images

Adding images the right way improves performance, accessibility, and SEO.

  • Always include alt text. Every image needs an alt attribute. It supports screen readers, displays when images fail to load, and helps search engines index your content.
  • Use descriptive file names. Name files based on their content — “beach-umbrella.png” instead of “image1.png.” This improves file organization and gives search engines additional context.
  • Compress your images. Large files slow down page load times. Use compression tools to reduce file size without sacrificing quality.
  • Choose the right file format. Use JPEG for photos and color-rich images. Use PNG for graphics that require transparency or sharp edges.
  • Control sizing with CSS. Set width and height properties in your HTML or CSS to maintain a consistent, responsive layout across all screen sizes.

Apply these practices to deliver fast-loading, accessible pages that perform well for users and search engines alike.

Troubleshooting image issues

Look, we’ve all been there — you’re building your web page and boom, broken image link. It’s usually something simple like a typo in that src attribute or maybe the image file decided to take a little vacation (got moved or deleted). Don’t worry, we’ve got you covered. Just double-check that file path in your img tag’s src attribute and make sure it actually matches where your image is hanging out.

Another thing that’ll drive you crazy? Pages that load slower than molasses because your images are huge. If your images are taking forever to show up, let’s fix that together. Try compressing those files or switch to a more efficient format — your visitors will thank you. And hey, make sure you’re using an image format that works with all major browsers, because nobody wants images that randomly stop showing up.

Still hitting some bumps? No problem — we’re here to help you troubleshoot this. Fire up your browser’s developer tools and take a peek at that image element on your page. It’s like having X-ray vision for spotting errors in file paths, checking if something’s getting blocked, or catching other sneaky issues. By systematically checking your src attribute, file size, and format, you’ll have those image problems sorted out in no time, and your images will appear exactly as they’re supposed to.

Bringing it all together: Inserting images in HTML

Adding images to your web pages is one of the most important parts of building a site people enjoy using. The key things to keep in mind: always include alt text (so your images are accessible to everyone), keep file sizes small to speed page load times, and choose the right file format for each image.

Get these basics right, and your images will look great on any device, load fast, and work for all visitors. When problems come up — like broken links or slow-loading files — they’re usually straightforward to fix.

Whether you’re using the img tag, adding background images with CSS, or experimenting with styling, knowing how to work with images is a core web development skill. It might feel like a lot at first, but the best practices covered here will help you build pages that don’t just look good — they perform well too.

To make managing your images even easier, consider a Digital Asset Management (DAM) tool like Canto. Digital asset management software makes it easy to store, organize, search for, manage, and distribute your organization’s content from a single place. — so your files are always easy to find and ready to use.

Frequently asked questions

How do you ensure images are responsive and adapt to different screen sizes in HTML?

To ensure images are responsive and adjust to different screen sizes in HTML, use the CSS `max-width` property set to `100%` and the ‘height’ property set to `auto`. This allows the image to scale down if necessary, but not beyond its original size, ensuring it adapts to its container’s width without losing its aspect ratio.

What are the key strategies for enhancing image optimization for the web to ensure quick loading times while maintaining high quality?

To effectively optimize images for web use, it’s essential to compress them to minimize file size without compromising their visual appeal. Adopting modern image formats such as WebP offers superior compression and quality compared to older formats like JPEG or PNG. Additionally, tailoring image dimensions to your website’s display requirements can eliminate unnecessary pixel data, further improving load times while preserving image integrity.

How can you add captions or descriptions directly below images in HTML to provide additional context or information?

Adding captions or descriptions directly below images can be done by wrapping the `<img>` tag and the caption text in a container, such as a `<figure>`, and using the `<figcaption>` tag for the caption. This semantic HTML approach provides a structured way to present images with their associated captions, improving accessibility and readability.

What is the difference between relative and absolute paths when inserting images in HTML?

Relative paths specify the location of an image file relative to the HTML file’s location, often used for images stored within the same project folder or subfolders. Absolute paths provide the full URL or path starting from the root directory or an external web server. Using relative paths makes your project more portable, while absolute paths are useful for linking to external images or when the image location is fixed.

Why is it important to include the alt attribute for images in HTML?

The alt attribute provides alternative text for images, which is crucial for accessibility, enabling screen readers to describe images to visually impaired users. It also serves as fallback text if the image fails to load and helps search engines understand the image’s content, improving SEO.

Can you use images hosted on external websites in your HTML code?

Yes, you can link to external images by using their full URL in the src attribute. However, this practice, known as hotlinking, is generally discouraged without permission because it uses the external site’s bandwidth and gives you no control over the image’s availability. It’s better to host images on your own web server or use authorized image hosting services.

How do width and height attributes affect image loading and page layout in HTML?

Specifying the width and height attributes in the <img> tag helps browsers allocate the correct space for the image before it loads, preventing layout shifts and improving the user experience. It also aids in faster rendering of page content, as the browser knows exactly how much space to reserve.

What file formats are best suited for different types of images on the web?

JPEG is ideal for photographs and images with rich color gradients due to its compression capabilities. PNG is well-suited for graphics that require transparency and sharp edges. SVG is perfect for logos and icons that need to scale without loss of quality. WebP offers superior compression and quality for general use, improving loading times without sacrificing image clarity.