HTML Images - The <picture> Element Quiz

Quiz 11 10 questions

Prerequisites for the quiz

  1. HTML Images — The <picture> Element

Are you ready?

10 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
The <picture> element is replacement for the <img> element in HTML. True or false?
Not at all. <picture> is only meant to provide more information to an <img> element on what image to render based on the current environment (i.e. the supported image types, the viewport's size, etc.). For more info, refer to HTML Images — The <picture> Element: What is the <picture> element?.
The source URL of the image represented by a <picture> element goes in its source attribute. True or false? If false, give the correct explanation.
The <picture> element doesn't hold the source URLs of any image whatsoever; this is the job of its constituent <source> elements, and even <img>. Hence, the correct choice is (D). For more info, refer to HTML Images — The <picture> Element.
A <picture> can have only as many as 10 <source> elements inside it. True or false?
False; we can have as many <source>s as we want to. For more info, refer to HTML Images — The <picture> Element: The <source> element.
What is the purpose of the <source> element inside a <picture>?
<source>, when inside a <picture>, serves to specify a source set of images (one or multiple images, varying in their resolution). This goes with choice (C). For more info, refer to HTML Images — The <picture> Element: The <source> element.
Is the <picture> element required to have at least one <source> element inside it?
No, a <picture> isn't required to have at least one <source> inside it. It's perfectly valid to have a <picture> without a <source>. (However, it's required for a <picture> to have one <img> in it.) For more info, refer to HTML Images — The <picture> Element.
The <picture> element can be used to ...
<picture> allows us to do all the things mentioned below except for choice (B). For more info, refer to HTML Images — The <picture> Element.

Bob wrote the following HTML code to serve the most appropriate image, in terms of format, for an illustration of cats:

<picture>
   <source type="image/jpeg" src="cats.jpg">
   <source type="image/avif" src="cats.avif">
   <source type="image/webp" src="cats.webp">
</picture>

The problem is that no matter what environment he tests this code in, the JPEG version of the given image gets loaded; the better formats, AVIF and WebP, never ever get loaded even if the browser supports them.

What's the issue in his code?
The ordering of the <source>s is problematic, specifically the one of the first <source>. The first <source> should come last because most browsers support JPG and we surely don't want to skip the rest of the <source>s from being seen when the JPG <source> comes first. Hence, the correct choice is (B). For more info, refer to HTML Images — The <picture> Element: The <source> element.
How can we use a <picture> to serve three different images (in terms of proportions) for different viewport sizes, and moreover, for each image, have two variants: normal-res, for devices with a DPR of 1, and high-res for a DPR of 2?
The <source> element inside <picture> will look after the three different images for different viewport sizes. Then, for each image, its two variants can be looked after by the srcset attribute of the corresponding <source>, containing the density descriptor 1x for the normal-res image and 2x for the high-res one. All in all, this goes with choice (B). For more info, refer to HTML Images — The <picture> Element.
Which of the following attributes of <source> specifies the type of the underlying source image?
The type attribute of the <source> element specifies the type (more specifically, the MIME type) of the underlying image. Hence, the correct choice is (B). For more info, refer to HTML Images — The <picture> Element: The <source> element.
The <picture> element can't do what a standalone <img> with a srcset attribute can. True or false?
False; essentially, a <picture> element can do everything — in fact, way beyond — what a standalone <img> with a srcset attribute can do. For more info, refer to HTML Images — The <picture> Element.

"I created Codeguage to save you from falling into the same learning conundrums that I fell into."

— Bilal Adnan, Founder of Codeguage