HTML & CSS interview question · Most asked
What is the alt attribute for, and what makes good alt text?
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
- What is ARIA, and what is the first rule of ARIA?
- What is HTML5, and how is it different from HTML 4?
- What is HTML?
- What is semantic HTML, and why does it matter?
- What input types and validation attributes did HTML5 add?
- What is the difference between script, script async and script defer?
- Compare localStorage, sessionStorage and cookies.
- What does <!DOCTYPE html> do?