Adding Images to Your Page

Hi, I'm Ahbab. In this article, I'll teach you how to add images to your web pages using HTML, along with best practices for optimizing and styling them.

What is the <img> Element?

The <img> element is used to embed images in HTML documents. It requires the src attribute to specify the image file and the alt attribute to provide alternative text for accessibility.

Example: Adding an Image

<img src="example.jpg" alt="Description of the image">
        

In this example, the src attribute specifies the image file, and the alt attribute provides a description for users who cannot see the image.

Best Practices for Using Images

Example: Responsive Images

<img src="example.jpg" alt="Description" style="max-width: 100%; height: auto;">
        

Adding style="max-width: 100%; height: auto;" ensures the image scales properly on different screen sizes.

Practice: Try It Yourself

  1. Project: Photo Gallery
    Create a web page with a gallery of images. Use the <img> element and style the images using CSS.
  2. Project: Profile Picture
    Add a profile picture to a personal bio page. Include a caption and style the image with borders and padding.

Continue Learning

Quick Check

Which attribute provides alternative text for images?