html images explain deeply: 18 MCQs with answers
All 18 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 6 questions
Q1. Which statement best describes what an `<img>` tag actually contains?
BeginnerShow answer & explanation
A pointer that tells the browser where to fetch the image
The `` tag does not store pixels. It is a placeholder that instructs the browser to fetch an external file and paint it in place. The actual image data lives in a separate file such as `.jpg` or `.png`.
Q2. A student writes `<img src="logo.png">` with no other attributes. Which attribute is missing that is required for accessibility?
BeginnerShow answer & explanation
`alt`
`alt` is the alternative-text attribute required for accessibility. Without it, screen readers may read the filename aloud and users on broken connections see nothing useful.
Q3. Which of these is a void element with no closing tag?
BeginnerShow answer & explanation
`<img>`
`` is a void element — it has no closing tag and cannot contain child content. The other three are container elements that wrap content.
Q4. A designer places a purely decorative divider image on a page. What should the `alt` attribute be?
BeginnerShow answer & explanation
`alt=""` (empty)
An empty `alt=""` tells assistive technology to skip the image, which is correct for decoration. Omitting `alt` entirely is worse because screen readers may then read the filename aloud.
Q5. Which format is the best choice for a photograph on a product page?
BeginnerShow answer & explanation
JPEG
JPEG is designed for photographs, producing small files with millions of colours. SVG is for vectors, GIF is limited to 256 colours, and PNG produces larger files for photographic content.
Q6. `<img>` is a void element, so it has no closing tag and cannot contain child content.
BeginnerShow answer & explanation
True
`` is a void element, so it has no closing tag and cannot contain child content.
Building up · 7 questions
Q7. A developer writes `<img src="hero.jpg" width="1200" height="600">`. What is the main benefit of including those HTML width and height attributes?
IntermediateShow answer & explanation
The browser reserves space early, preventing layout shift
HTML `width` and `height` communicate the intrinsic aspect ratio so the browser can reserve the correct box before the file arrives. This prevents the text-jumping layout shift when the image finally loads.
Q8. A page has a large footer logo far below the fold. Which attribute should be added to defer its download?
IntermediateShow answer & explanation
`loading="lazy"`
`loading="lazy"` defers off-screen images until the user scrolls near them. This is one of the cheapest performance wins available in HTML.
Q9. A developer writes: ```html <img src="small.jpg" srcset="small.jpg 480w, medium.jpg 1024w, large.jpg 1920w" sizes="(max-width: 600px) 480px, 1024px" alt="Mountain landscape"> ``` What does the browser do with this markup?
IntermediateShow answer & explanation
Picks the smallest suitable file based on the `sizes` hint
The `w` descriptors declare each file's real pixel width, and `sizes` tells the browser how wide the image will render at each breakpoint. The browser then downloads only the file that fits, saving bandwidth.
Q10. Why is omitting the `alt` attribute worse than writing `alt=""`?
IntermediateShow answer & explanation
Because screen readers may read the filename aloud
An empty `alt=""` deliberately silences decoration. Omitting `alt` entirely leaves assistive tech to fall back on the filename, which is more confusing than silence.
Q11. A developer sets `<img src="a.jpg" width="500">` and assumes this is the same as CSS sizing. Why is this assumption wrong?
IntermediateShow answer & explanation
HTML `width` sets the intrinsic aspect-ratio hint; CSS controls rendered size
The HTML `width` and `height` attributes tell the browser the intrinsic aspect ratio so it can reserve space early. CSS `width` and `height` control the rendered size. Best practice is to set both.
Q12. A news site serves crisp photos to retina phones without punishing desktop users. Which pair of attributes makes this possible?
IntermediateShow answer & explanation
`srcset` and `sizes`
`srcset` offers multiple files at different widths, and `sizes` tells the browser how wide the image will render at each breakpoint. Together they let the browser pick the right file for each device.
Q13. Which of these is NOT a reason `alt` text matters?
IntermediateShow answer & explanation
It reduces the image file size on disk
`alt` serves accessibility, broken-image fallback, and SEO. It has no effect on the file size of the image itself — that is determined by the format and compression.
Topper level · 5 questions
Q14. A developer needs an icon that stays sharp at any zoom level and has a tiny file size. Which format fits best?
AdvancedShow answer & explanation
SVG
SVG is vector-based, so it scales infinitely without quality loss and produces very small files for icons and charts. Raster formats like JPEG, PNG, and GIF would blur or bloat at large sizes.
Q15. A team is choosing between a 2 MB PNG and a 150 KB JPEG for a photograph that will look identical either way. Which is the better choice for a performance-conscious page?
AdvancedShow answer & explanation
The JPEG, because it delivers the same look at a fraction of the bytes
Matching format to content is one of the highest-leverage performance decisions on a page. A 2 MB PNG photograph where a 150 KB JPEG looks identical is a real, common waste that slows the page.
Q16. A developer is deciding between `<img>` and CSS `background-image` for a product photo that customers should be able to right-click and save. Which is the better choice and why?
AdvancedShow answer & explanation
`<img>`, because it is real content that supports alt text and saving
Meaningful content belongs in ``, which supports `alt` text, right-click saving, and SEO value. CSS `background-image` is for decoration and often does not allow saving.
Q17. A developer is optimizing a webpage that includes multiple images. They want to ensure that images below the fold do not start downloading until they are about to be viewed. Which attribute should they use in their `<img>` tags to achieve this?
AdvancedShow answer & explanation
loading='lazy'
The correct option is `loading='lazy'`, which defers the loading of off-screen images until the user scrolls near them, improving page load performance.
Q18. A web developer is tasked with creating a responsive image solution for a product page. They want to ensure that the browser selects the most appropriate image size based on the device's screen width. They write the following code: ```html <img src='small.jpg' srcset='small.jpg 480w, medium.jpg 1024w, large.jpg 1920w' sizes='(max-width: 600px) 480px, 1024px' alt='Product image'> ``` What will happen if the browser's viewport is 500 pixels wide?
AdvancedShow answer & explanation
The browser will download 'medium.jpg'.
The correct option is that the browser will download 'medium.jpg' because the viewport width of 500 pixels falls within the range specified in the `sizes` attribute, which indicates that the image should be displayed at 1024 pixels.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages