🖼️ Mastering Image Tags in HTML (With Semantics)

🖼️ Mastering Image Tags in HTML (With Semantics)

Images make our websites engaging, but to make them accessible and meaningful, we need to use the right semantic HTML tags. Let’s break it down step by step.

🔹 1. The Basic <im…


This content originally appeared on DEV Community and was authored by Sharad Aade

🖼️ Mastering Image Tags in HTML (With Semantics)

Images make our websites engaging, but to make them accessible and meaningful, we need to use the right semantic HTML tags. Let’s break it down step by step.

🔹 1. The Basic <img> Tag

The simplest way to add an image:

<img src="sunset.jpg" alt="Sunset over the mountains">
  • src → file path of the image
  • alt → alternative text (important for accessibility & SEO)

🔹 2. Grouping Images With <figure>

Use <figure> when an image is self-contained and part of the content.

<figure>
  <img src="sunset.jpg" alt="Sunset over the mountains">
</figure>

👉 This tells the browser and screen readers: “This image is an independent piece of content.”

🔹 3. Adding Captions With <figcaption>

Captions explain the image. Place <figcaption> inside <figure>.

<figure>
  <img src="sunset.jpg" alt="Sunset over the mountains">
  <figcaption>A beautiful sunset view in the Himalayas.</figcaption>
</figure>

🔹 4. Responsive Images With <picture>

Sometimes, you want different images for mobile and desktop.

<figure>
  <picture>
    <source media="(min-width: 800px)" srcset="sunset-large.jpg">
    <source media="(min-width: 400px)" srcset="sunset-medium.jpg">
    <img src="sunset-small.jpg" alt="Sunset over the mountains">
  </picture>
  <figcaption>Sunset — shown in different sizes depending on screen.</figcaption>
</figure>

🔹 5. Clickable Areas With usemap

The usemap attribute allows you to define hotspots in an image that link to different places.

<figure>
  <img src="world-map.jpg" alt="World Map" usemap="#worldmap">

  <map name="worldmap">
    <!-- Rectangular area -->
    <area shape="rect" coords="50,50,200,150" href="https://en.wikipedia.org/wiki/India" alt="India">

    <!-- Circular area -->
    <area shape="circle" coords="400,200,50" href="https://en.wikipedia.org/wiki/Australia" alt="Australia">

    <!-- Polygonal area -->
    <area shape="poly" coords="600,100,650,150,700,120" href="https://en.wikipedia.org/wiki/Japan" alt="Japan">
  </map>

  <figcaption>Clickable world map — each area links to a different country.</figcaption>
</figure>
  • usemap="#id" → connects <img> to a <map>
  • <area> → defines clickable shapes (rect, circle, poly)
  • coords → pixel coordinates for the shape
  • alt → accessibility label

👉 This is useful for diagrams, maps, product images, etc.

🎯 Final Semantic Example

<article>
  <h2>Travel to the Himalayas</h2>
  <figure>
    <picture>
      <source srcset="himalaya.avif" type="image/avif">
      <source srcset="himalaya.webp" type="image/webp">
      <img src="himalaya.jpg" alt="Snow-covered Himalayan peaks" usemap="#himalaya-map">
    </picture>

    <map name="himalaya-map">
      <area shape="circle" coords="250,200,50" href="everest.html" alt="Mount Everest">
    </map>

    <figcaption>The Himalayan range with a clickable area linking to Everest.</figcaption>
  </figure>
</article>

✅ Best Practices

  • Always add alt text
  • Use <figure> + <figcaption> for meaning
  • Use <picture> for responsive images
  • Use usemap for interactive clickable regions
  • Test clickable areas on different screen sizes


This content originally appeared on DEV Community and was authored by Sharad Aade


Print Share Comment Cite Upload Translate Updates
APA

Sharad Aade | Sciencx (2025-09-13T05:35:17+00:00) 🖼️ Mastering Image Tags in HTML (With Semantics). Retrieved from https://www.scien.cx/2025/09/13/%f0%9f%96%bc%ef%b8%8f-mastering-image-tags-in-html-with-semantics/

MLA
" » 🖼️ Mastering Image Tags in HTML (With Semantics)." Sharad Aade | Sciencx - Saturday September 13, 2025, https://www.scien.cx/2025/09/13/%f0%9f%96%bc%ef%b8%8f-mastering-image-tags-in-html-with-semantics/
HARVARD
Sharad Aade | Sciencx Saturday September 13, 2025 » 🖼️ Mastering Image Tags in HTML (With Semantics)., viewed ,<https://www.scien.cx/2025/09/13/%f0%9f%96%bc%ef%b8%8f-mastering-image-tags-in-html-with-semantics/>
VANCOUVER
Sharad Aade | Sciencx - » 🖼️ Mastering Image Tags in HTML (With Semantics). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/13/%f0%9f%96%bc%ef%b8%8f-mastering-image-tags-in-html-with-semantics/
CHICAGO
" » 🖼️ Mastering Image Tags in HTML (With Semantics)." Sharad Aade | Sciencx - Accessed . https://www.scien.cx/2025/09/13/%f0%9f%96%bc%ef%b8%8f-mastering-image-tags-in-html-with-semantics/
IEEE
" » 🖼️ Mastering Image Tags in HTML (With Semantics)." Sharad Aade | Sciencx [Online]. Available: https://www.scien.cx/2025/09/13/%f0%9f%96%bc%ef%b8%8f-mastering-image-tags-in-html-with-semantics/. [Accessed: ]
rf:citation
» 🖼️ Mastering Image Tags in HTML (With Semantics) | Sharad Aade | Sciencx | https://www.scien.cx/2025/09/13/%f0%9f%96%bc%ef%b8%8f-mastering-image-tags-in-html-with-semantics/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.