📸 HTML5 Tags: (Image) Tag

📸 HTML5 Tags: <img> (Image) Tag

Images don’t speak, but in HTML they tell a lot

Hello dear code wizard 🧙‍♂️💻
Today, we’re face to face with one of the quietest yet most powerful characters in the HTML world: the <img> tag.

This tag doesn’t talk, has no closing tag, doesn’t cause drama like JavaScript… but it can completely change the fate of a web page.
When used incorrectly:

  • ❌ Broken image icon
  • ❌ Slow page
  • ❌ SEO getting mad at you

When used correctly:

  • ✅ Professional look
  • ✅ Fast website
  • ✅ Google saying: “This developer knows what they’re doing” 😎

If you’re ready, let’s begin. Grab your coffee ☕, we’re opening the images!


🧱 What Is <img> and What Is It Not?

The <img> tag is used to add images to an HTML page. But there’s a small detail:

The <img> tag is self-closing. That means it has NO closing tag.

❌ Wrong usage:

&lt;img src="photo.jpg">&lt;/img>

✅ Correct usage:

&lt;img src="photo.jpg" alt="Description text">

🧠 Browser logic:
“I’ve seen this tag. Okay, rendering the image.”


🔑 Core Attributes – The Kitchen of the Job 🍳

📌 src — The Image Address

src (source) tells the browser where the image comes from.

&lt;img src="images/cat.jpg" alt="Sleeping cat">

📂 If the image is in the same folder:

&lt;img src="cat.jpg" alt="Cat">

🌍 If it comes from the internet:

&lt;img src="https://site.com/cat.png" alt="Online cat">

⚠️ Tips:

  • File names are case-sensitive (Cat.jpgcat.jpg)
  • Avoid special/local characters → they cause pain later 😭

🧠 alt — The Silent Hero

The alt text is for:

  • Screen readers
  • SEO
  • Users when the image fails to load
&lt;img src="dog.jpg" alt="Golden retriever dog playing with a ball">

❌ Bad alt text:

alt="image1"

✅ Good alt text:

alt="Developer working at a computer">

📢 Rule:

Write the alt text as if you’re describing the image to someone who can’t see it.


📐 width and height — The Size Matter

&lt;img src="landscape.jpg" alt="Mountain landscape" width="400" height="250">

But in the modern world, we usually use CSS, not HTML:

img {
  max-width: 100%;
  height: auto;
}

📱 What does this give you?

  • Mobile compatibility
  • No overflow
  • Responsive design ❤️

⚡ Performance Tips – Make Your Site Fly 🚀

💤 loading="lazy"

&lt;img src="large-image.jpg" alt="Long page image" loading="lazy">

🧠 The browser says:

“I’ll load it when the user scrolls down.”

Result:

  • Faster page load ⚡
  • Happier users 😄

🗜️ Reduce Image Size

HTML doesn’t resize images — it only displays them.

❌ Uploading a 5000px image and saying width=300

✅ Optimize your images:

  • Use WebP
  • Tools like TinyPNG, ImageOptim

🧩 Professionalism with <figure> and <figcaption>

&lt;figure>
  &lt;img src="forest.jpg" alt="Misty forest landscape">
  &lt;figcaption>6 AM, no coffee, motivation at 3% 🌫️&lt;/figcaption>
&lt;/figure>

🎯 What did you gain?

  • Semantic HTML
  • Better SEO
  • Meaningful structure

🚫 Most Common Mistakes (Don’t Do These 🙃)

  • ❌ Not writing alt text
  • ❌ Treating images like backgrounds
  • ❌ Using PNG everywhere
  • ❌ Messy file paths

🧪 Mini Practical Example

&lt;!DOCTYPE html>
&lt;html lang="en">
&lt;head>
  &lt;meta charset="UTF-8">
  &lt;title>Img Tag Demo&lt;/title>
  &lt;style>
    img { max-width: 100%; height: auto; }
  &lt;/style>
&lt;/head>
&lt;body>
  &lt;h1>Profile Card&lt;/h1>
  &lt;img src="profile.jpg" alt="Smiling developer">
&lt;/body>
&lt;/html>


🎯 TL;DR of the TL;DR

  • <img> has no closing tag
  • src gives the address, alt gives the meaning
  • Control size with CSS
  • Don’t forget performance
  • Image = content

🚀 Final Words

Adding an image in HTML is easy.
But adding it correctly, fast, accessible, and meaningful is what makes you a real developer 😎

Comments

No comments yet. Why don’t you start the discussion?

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir