Lesson 15 of 30
Every image and icon needs one of exactly two treatments: marked as decorative and skipped entirely, or given real, specific alt text describing what it means. A missing alt attribute is neither — and is its own, different problem.
11 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
What's the difference between an <img> with a missing alt attribute and one with alt=""?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Every image or icon in an interface falls into one of two categories, and the correct markup depends entirely on which one it is.
A decorative image contributes nothing informational — a background flourish, a redundant icon sitting right next to text that already says the same thing. It should be explicitly marked so assistive technology skips it silently: alt="" on an <img> (an empty string, deliberately set — not a missing alt attribute, which is a different, worse problem some screen readers handle by announcing the image's filename instead), or aria-hidden="true" on a decorative icon element that isn't an <img>.
An informative image conveys something a user needs — it needs real, specific alt text describing what it means in context. Not a lazy alt="image", not the filename, and not an exhaustive visual description of every detail that isn't relevant to why the image is there. Good alt text describes the image's function or meaning, not its full visual content — a photo used as a "delete this profile picture" button's icon should have alt text describing the action, not a description of what's in the photo.
<!-- Broken: no accessible name for the button at all -->
<button>
<svg><path d="..." /></svg>
</button>
<!-- Fixed: aria-label supplies the missing accessible name -->
<button aria-label="Delete conversation">
<svg role="img" aria-hidden="true"><path d="..." /></svg>
</button>
A button holding only an SVG icon — a trash can, no visible text — has no text content for a screen reader to read as its accessible name, so by default it announces as an unlabeled, empty button. This connects directly back to how accessible names are computed generally: an element's accessible name comes from its text content, aria-label, or a labelling relationship, and an icon-only button has none of the first unless it's given one of the other two. aria-label="Delete conversation" on the <button> is the direct fix, giving the control a real accessible name independent of what's visually inside it.
alt attribute and alt="" are not the same thing. Missing alt is flagged as an accessibility error and some screen readers fall back to announcing the filename; alt="" is a deliberate, explicit "skip this" signal that only works when actually present.role="img" plus aria-label or <title>) — simply having a <path> with meaningful visual content doesn't make an SVG announce anything on its own.aria-hidden="true" removes an element from the accessibility tree entirely, including from focus-based navigation in some cases — it should never be applied to something a keyboard or screen reader user actually needs to interact with, only to genuinely decorative content."This icon-only button has no visible label — how do you fix it for screen reader users?" is a real, common question, and naming aria-label specifically (plus explaining why the icon-only case has no other source for an accessible name) is the concrete answer interviewers are listening for.