HTML & CSS interview question · Most asked

What is the alt attribute for, and what makes good alt text?

Create a free account to save this page, take notes and track your progress. Sign in

Summary

alt provides a text alternative for an image, read by screen readers and shown when the image fails to load; search engines use it too. Good alt text briefly conveys what the image means in context. Decorative images get an empty alt="" so screen readers skip them.

Longer Answer

Don't start with "image of" (screen readers already say it's an image), don't repeat nearby text, and describe the purpose for functional images: a linked logo's alt is the destination ("ReadyCamel home"), not "logo". Missing alt entirely is the worst case: some screen readers read the file name.

Key Points

  • Text alternative for images.
  • Describe meaning in context.
  • alt="" for decoration.
  • Never omit alt.

Deep dive: HTML5 for Beginners: Images

Explanation

What interviewers look for

The empty-alt rule for decorative images and context-dependent descriptions.

More most-asked HTML & CSS questions

← All HTML & CSS questions

Was this page helpful?