What if your beautiful image disappears--will your message vanish too?
Why Image source and alt attribute in HTML? - Purpose & Use Cases
Imagine you want to show a picture on your webpage. You type the image's file path directly into your code without any description.
If the image file is missing or slow to load, visitors see a broken icon or nothing at all. Also, people using screen readers or with slow internet miss out because there is no text to explain the image.
Using the src attribute tells the browser where to find the image, and the alt attribute provides a text description. This helps everyone understand what the image is, even if it doesn't load or if they use assistive tools.
<img src="photo.jpg"><img src="photo.jpg" alt="A smiling child playing in the park">
This makes your website more reliable, accessible, and friendly to all users, no matter how they browse.
Think about a news site showing a photo of a protest. If the image doesn't load, the alt text can say "People holding signs at a peaceful protest," so readers still get the message.
Always use src to link your image file.
Use alt to describe the image for accessibility and fallback.
This helps everyone understand your content better.