💡 Tip: Login now to track your course progress and unlock your downloadable certificates instantly!

HTML Images

Images make a webpage more engaging and visually appealing. HTML allows you to display images using the <img> tag, which is an empty tag (it doesn’t have a closing tag). You can insert photos, illustrations, icons, and other graphics directly into your webpage.

The <img> Tag

The basic syntax for adding an image is:

Basic Image Tag
<img src="image.jpg" alt="Description of the image">

Explanation:

  • src (source): Specifies the path or URL of the image.
  • alt (alternative text): Provides descriptive text if the image cannot be displayed. It also helps with accessibility and SEO.

Adding Image Width and Height

You can control the display size of an image using the width and height attributes:

Image Example
<img src="image.jpg" alt="A sample image" width="300" height="200">

⚠️ Tip: It’s better to control image size with CSS for responsive design.

Image from a Folder

If your image is stored in a subfolder, specify the relative path:

Image from Folder
<img src="images/picture.jpg" alt="Picture inside folder">

If the image is hosted online, you can use an absolute URL:

Image from Online
<img src="https://example.com/photo.jpg" alt="Online image">

Image as a Link

You can make an image clickable by placing it inside an <a> tag:

Image as a Link
<a href="https://html5andcss3.org">
  <img src="https://html5andcss3.org/wp-content/uploads/2025/10/html5_and_css3_logo.webp" alt="HTML5 & CSS3 Logo" width="150">
</a>

Image Title Attribute

The title attribute adds a tooltip text when users hover over the image:

Image Title Example
<img src="flower.jpg" alt="Rose" title="A beautiful rose">

Responsive Images with CSS

To make your images adjust automatically on different screen sizes, use CSS:

Responsive Image Example
<img src="mountain.jpg" alt="Mountain view" style="width:100%; height:auto;">

This ensures the image scales correctly across all devices.

Image Alignment (Modern Way)

In older HTML, people used align attribute (now deprecated).
The modern and better way is to use CSS:

Image Alignment Example
<img src="https://html5andcss3.org/wp-content/uploads/2025/10/html5_and_css3_logo.webp" alt="Photo" style="display:block; margin:auto;">

This centers the image horizontally.

Alternative Text Importance (Alt Tag)

The alt attribute is crucial for:

  • SEO optimization
  • Screen readers for visually impaired users
  • Displaying fallback text when the image is missing

Always use descriptive alt text relevant to the image content.

Example: Complete Image Code

Complete Image Example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HTML Image Example</title>
</head>
<body>

  <h2>Example of an Image in HTML</h2>
  <a href="https://html5andcss3.org">
    <img src="https://html5andcss3.org/wp-content/uploads/2025/10/html5_and_css3_logo.webp" alt="HTML5 Logo" width="200" style="display:block; margin:auto;">
  </a>
  <p>This is an example of how to add and center an image in HTML.</p>

</body>
</html>

Best Practices

  • Use <img> tag with src and alt attributes.
  • Use width, height, and CSS for responsive styling.
  • Wrap images in <a> tags for clickable images.
  • Always include descriptive alt text for accessibility.

Conclusion

Images are an essential part of modern web design. They help communicate ideas, showcase products, and enhance the visual appeal of your website. In HTML, the <img> tag is simple yet powerful — allowing you to insert, resize, and link images effortlessly.

By combining proper attributes (src, alt, width, height) and modern CSS styling, you can create responsive, accessible, and fast-loading visuals that improve both user experience and SEO performance.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend