Chapter 6: Adding Images in HTML

Images are essential in web design. Let’s learn how to use the <img> tag in HTML, style images with CSS, and even update them using JavaScript — all without leaving this page!

1. Basic Image

The <img> tag inserts an image using the src attribute for the path and alt for alternative text.

This will show a placeholder image with a width and height of 150px.

2. Image with Width and Height

You can add width and height to an image for layout control.

This shows how to scale an image using HTML attributes.

3. Responsive Image with CSS

Use CSS to make images responsive, meaning they adjust to different screen sizes.

This image scales to fit its container without distortion.

4. Clickable Image

Wrap an image with a link to make it clickable.

This image links to another webpage when clicked.

5. Changing Image with JavaScript

You can dynamically update an image source with JavaScript. This can be useful for image galleries or product views.

Clicking the button will change the image using JavaScript.