Course Content
Introduction to HTML
In this introductory module, you'll learn what HTML is and its role in web development. You will set up your development environment and create your first HTML page. You'll also understand the basic structure of an HTML document and get familiar with fundamental HTML elements and attributes.
0/4
Working with Text in HTML
This module covers how to format text in HTML, including creating headings, paragraphs, and lists. You'll learn how to emphasize text with bold, italics, and underline, and how to create links for navigation. You'll also explore text alignment and introduce inline CSS for basic styling.
0/4
Working with Images and Multimedia
In this module, you’ll learn how to add images and multimedia to your HTML pages. You'll master the <img> tag, and understand how to work with attributes like src and alt. Additionally, you'll discover how to embed audio and video files directly into your webpage, enhancing its interactivity.
0/3
Tables and Forms in HTML
This module introduces the use of tables for displaying structured data and forms for collecting user input. You'll learn how to create, format, and style tables, and how to build forms with input fields, checkboxes, and buttons. Basic HTML5 form validation will also be covered.
0/2
HTML5 Elements and Semantic Markup
Explore the power of HTML5 in this module, where you’ll learn about new HTML5 elements like <article>, <section>, and <nav>. You’ll gain an understanding of semantic HTML, which helps improve search engine optimization (SEO) and accessibility. You’ll also be introduced to HTML5-specific features such as video and audio embedding.
0/3
Advanced HTML Concepts
This module dives deeper into advanced HTML topics, including embedding external content using [iframe], working with HTML5 APIs like geolocation, and implementing accessibility best practices with ARIA attributes. You’ll also get a primer on responsive web design with the use of meta tags and media queries.
0/4
HTML Best Practices
Learn the best practices for writing clean, maintainable, and accessible HTML. This module covers proper code formatting, the importance of semantic HTML, and how to structure your HTML for SEO. You’ll also get practical tips on debugging HTML and using online validators to ensure your code is error-free.
0/3
Project – Building a Simple Website
Apply everything you’ve learned by creating a complete website from scratch in this hands-on project. You’ll plan, design, and build a multi-page website, incorporating text, images, forms, and navigation. This project will help you solidify your skills and showcase your work.
0/4
Conclusion and Next Steps
In the final module, you'll review the key concepts and skills you’ve learned throughout the course. You’ll also get guidance on the next steps in your web development journey, including an introduction to CSS for styling and JavaScript for interactivity. You’ll complete a final assessment to demonstrate your new HTML skills.
0/2
Complete HTML Course (Free)
About Lesson

Adding Images

This lesson will guide you on how to add images to your web pages using HTML. You will learn about the <img> tag, its attributes, and best practices for including and styling images.


1. Why Use Images in Web Pages?

Images enhance the visual appeal of a website, help convey information more effectively, and engage users. They can be used as illustrations, icons, backgrounds, or to complement text content.


2. The <img> Tag

The <img> tag is used to embed images in an HTML document. It is a self-closing tag, meaning it doesn’t require a closing tag.

Syntax:

<img src="image_path" alt="description" />

Key Attributes:

  1. src (Source): Specifies the path to the image file.
  2. alt (Alternative Text): Provides a text description for the image, which is essential for accessibility and is displayed if the image fails to load.

3. Adding Images to a Web Page

  1. Embedding a Local Image:

    • Place the image file in the same directory as your HTML file or specify the correct relative path.
      <img src="image.jpg" alt="A sample image" />
      
  2. Embedding an Online Image:

    • Use the full URL of the image as the src.
      <img src="https://example.com/image.jpg" alt="A sample online image" />
      

4. Common <img> Attributes

  1. width and height:

    • Specify the dimensions of the image in pixels or percentage.
      <img src="image.jpg" alt="A sample image" width="300" height="200" />
      
  2. title:

    • Adds a tooltip that appears when the user hovers over the image.
      <img src="image.jpg" alt="A sample image" title="Hover text example" />
      
  3. loading:

    • Optimizes performance by controlling how images load.
      • lazy: Loads the image only when it’s visible in the viewport.
      <img src="image.jpg" alt="A sample image" loading="lazy" />
      

5. Example: Adding and Styling Images

<!DOCTYPE html>
<html>
<head>
    <title>Adding Images Example</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
        }
        .responsive {
            max-width: 100%;
            height: auto;
        }
    </style>
</head>
<body>
    <h1>Adding Images in HTML</h1>
    <p>Here is an example of an embedded image:</p>
    <img src="example.jpg" alt="A beautiful landscape" width="500" />
    <p>This image is styled to be responsive:</p>
    <img src="example.jpg" alt="A responsive image example" class="responsive" />
</body>
</html>

6. Advanced Usage of Images

  1. Using Images as Links:

    • Wrap an image inside an <a> tag to make it clickable.
      <a href="https://example.com">
          <img src="image.jpg" alt="Click to visit example.com" />
      </a>
      
  2. Background Images (CSS):

    • Add images as background elements using CSS.
      body {
          background-image: url('background.jpg');
          background-size: cover;
          background-repeat: no-repeat;
      }
      
  3. Image Maps:

    • Create clickable areas within an image using the <map> tag and <area> elements.
      <img src="map.jpg" alt="Clickable map" usemap="#imagemap" />
      <map name="imagemap">
          <area shape="rect" coords="34,44,270,350" href="link1.html" alt="Link 1" />
          <area shape="circle" coords="337,300,44" href="link2.html" alt="Link 2" />
      </map>
      

7. Best Practices for Adding Images

  1. Use Optimized Images:

    • Compress images to reduce file size and improve page load speed.
  2. Provide Descriptive alt Text:

    • Describe the image content clearly for accessibility and SEO.
  3. Ensure Responsiveness:

    • Use CSS or set max-width: 100% to ensure images adapt to various screen sizes.
  4. Lazy Loading:

    • Use the loading="lazy" attribute to delay image loading, improving performance on pages with many images.
  5. Organize Images:

    • Store images in a dedicated folder (e.g., /images) for better organization.

8. Hands-On Activity: Adding Images

  1. Create a folder and include an HTML file (index.html) and an image file (landscape.jpg).
  2. Add the following code:
    <!DOCTYPE html>
    <html>
    <head>
        <title>Image Example</title>
    </head>
    <body>
        <h1>Adding Images</h1>
        <p>Here is an example of an embedded image:</p>
        <img src="landscape.jpg" alt="A beautiful landscape" />
    </body>
    </html>
    
  3. Open the HTML file in your browser to see the image displayed.

9. Summary

  • Images are added using the <img> tag with attributes like src, alt, width, and height.
  • Images can be embedded from local directories or online sources.
  • Styling images with CSS ensures they adapt to various devices and layouts.
  • Following best practices like optimizing images and adding alt text improves performance and accessibility.