<img> Tag — HTML Technical Interview Questions & Answers

Embeds an image into the page.

<img> Tag

  • Embeds an image into the page.
  • <img> is an image. HTML uses this tag so the browser (and screen readers) know what the piece is, not only how it looks.
  • Board: <img src="photo.jpg" alt="Asha"> Put it in body. Check it in the browser. Attributes go on the opening tag.
  • Trap: empty alt on a real photo. CSS can still style it — don’t pick a tag only because of default italics.
  • Interview: name the tag, one attribute if it has a famous one (href, src, alt, for, type), one mistake.

Technical Interview Tip: <img>: an image. Example: <img src="photo.jpg" alt="Asha">

Code Examples for <img> Tag

<img> Tag — working example

<figure>
  <picture>
    <source media="(max-width: 640px)" srcset="/photos/team-sm.jpg" />
    <img
      src="/photos/team.jpg"
      alt="Students practicing interview questions at a workshop"
      width="480"
      height="320"
      loading="lazy"
    />
  </picture>
  <figcaption>Weekend mock-interview workshop</figcaption>
</figure>

<link rel="icon" href="/favicon.ico" sizes="any" />

<img> Tag — alt describes the image; picture/srcset adapt assets; figure/figcaption caption media.

How to Explain <img> Tag to an Interviewer

What is the <img> tag?

an image <img src="photo.jpg" alt="Asha">

One common mistake?

empty alt on a real photo