switzCodes blog banner titled 'Adding Images with <img> – Making Web Pages Visual' 
                    in navy blue with white and green shapes

πŸ–ΌοΈ Adding Images with <img> - Making Web Pages Visual

πŸ“… August 15, 2025

✍️ By Evans

Hey there, friends! πŸ‘‹

After learning how to add links with the <a> tag, I wanted to make my pages look a bit more alive. Words are cool, but visuals? They make your page pop! πŸ’₯

That's when I learned about the <img> tag β€” the HTML tag used to add images to a web page.

Let's jump right in! πŸ–ΌοΈ

🧱 The Basic Image Tag

Heres the simplest way to add an image in HTML:


<img src="myphoto.jpg" alt="A picture of me learning HTML">
                            

Let's break that down:

  • <img> is the tag β€” and it doesn't need a closing tag!
  • src (source) tells the browser where to find the image.
  • alt (alternative text) describes the image β€” super important for accessibility and when the image fails to load.

πŸ’‘ Example:

If your image doesn't load, the text from alt appears instead. It also helps screen readers describe images to visually-impaired users.

πŸ—‚οΈ Linking to Images in Folders

If your image is inside a folder, you just include the folder name in the path:


<img src="images/profile.jpg" alt="Evans' profile photo">
                            

That tells the browser to look for the image inside the images/ folder

🌍 Using Online Images

You can also add images directly from the internet β€” just use the full URL:


<img src="https://example.com/pic.jpg" alt="Cool online picture">
                        

⚠️ Be careful though β€” if that image is deleted or moved, it won't show up on your page anymore.

πŸ“ Setting Image Size

You can control the width and height of images with attributes or, better yet, CSS:


<img src="photo.jpg" alt="Example" width="300" height="200">
                        

But using CSS gives you more flexibility later on:


<img src="photo.jpg" alt="Example" style="width: 300px; height: auto;">
                        

Using height: auto; keeps the image from stretching weirdly. πŸ˜…

πŸ“Œ My Mistakes at First

  • ❌ Forgot to put the image in the right folder
  • ❌ Misspelled the image name (e.g. Photo.JPG instead of photo.jpg)
  • ❌ Didn't add alt, so when the image didn’t load, it just looked broken

πŸ™‹β€β™‚οΈ Why alt is Important

esides helping with accessibility (for users using screen readers), the alt text also shows when the image can't load.

For example:


<img src="wrongname.jpg" alt="My profile picture">
                        

If the image is missing, users will at least see β€œMy profile picture” instead of nothing.

πŸ–Ό My Practice Page


<h1>Welcome to Evans Blog</h1>
<p>Here's a photo from when I started learning HTML:</p>

<img src="images/learning.jpg" alt="Me coding at night" width="400">
                        

🎯 What I Learned

The <img> tag taught me that HTML isn't just about text β€” it's about visual storytelling. Adding images made my pages feel more real and exciting to look at. It's that β€œwow” moment when your blank page finally starts to look like a real website. 😍

πŸ‘‰ What's Next?

Next up, I'll be learning about Lists in HTML - Ordered and Unordered Lists.

We'll look at how to organize information neatly using <ul>, <ol>, and <li> tags.

Thanks again for reading, catch you in the next post!

β€” Evans πŸ“ΈπŸ’»