Web Technology Questions and Answers – Adding Images using the IMG Element

This set of Web Technology Multiple Choice Questions & Answers (MCQs) focuses on “Adding Images using the IMG Element”.

1. How many attributes are at least needed for <img> element?
a) 1
b) 2
c) 3
d) 5
View Answer

Answer: b
Explanation: The <img> element must carry at least two attributes which are src attribute and alt attribute. The src attribute indicates the source of the image. An alt attribute provides a description of the image.

2. Proper syntax to use alt attribute is?
a) < img src=”logo.gif” alt=”name of logo” / >
b) <img alt=”name of logo”/>
c) <img src=”logo.gif” />
d) <img src=”logo.gif alt=”name of lago”/>
View Answer

Answer: a
Explanation: As minimum two attributes are needed, alt attribute should be followed by src attribute. <img> is used to upload an image on a webpage. Src attribute indicates the source of image. While, the alt attribute serves as an alternative option to view image when it describes about the image.

3. If an image doesn’t add any information to the page, which of the following statement is correct?
a) < img src=”logo.gif” alt=”name of logo” / >
b) < img src=”” alt=”name of logo” / >
c) < img src=”logo.gif” alt=”” / >
d) < img alt=”” / >
View Answer

Answer: d
Explanation: Following the src attribute, the alt attribute should be written with nothing in between the double inverted commas. Generally, If the browser cannot display the image, this text alternative will be shown instead. Web users with visual impairments often use software called a screen reader to read a page to them, in which case the alt text describes the image they cannot see.
advertisement
advertisement

4. What is a containing element?
a) The image inside an element that takes up the whole page
b) The image which is completely outside/on different page
c) The image inside an element that takes up only part of the page
d) An element inside an element is not possible
View Answer

Answer: c
Explanation: Technically, the values of attributes can be a percentage of the browser screen. If you do use a percentage, the number will be followed by a percent sign. Showing an image at any size other than the size at which it was created can result in a distorted or fuzzy image.

5. What happens when only the width of the image is displayed and not height?
a) It only shows the image by its width
b) It tries to maintain the aspect ratio
c) It shows the image by equal height and width as mentioned
d) Shows an error by not displaying any image
View Answer

Answer: b
Explanation: If you said that the image was 100 pixels wide and did not specify the height, the browser would try to make the image 50 pixels tall. Because it is 50 percent the width of the original image, it would display the image at 50 percent of its height. The aspect ratio is its width divided by height.

6. Which of the following is an align value that isn’t a part of HTML specification?
a) top
b) absbottom
c) middle
d) left
View Answer

Answer: b
Explanation: The values absbottom, texttop, absmiddle and baseline are not part of the XHTML specification. They were added by the browser manufacturers and therefore can produce inconsistent results. While the common align values are top, middle, bottom, left, right.

7. The vspace and hspace attribute is used to ___________
a) control the amount of white space around an image
b) control the border around an image
c) control width and height of an image
d) control the alignment of an image
View Answer

Answer: a
Explanation: The value is the amount in pixels of white space that should be left around the edge of the image. It is similar to the image having a border around the image that is the same color as the background of the page. Before CSS, the hspace and vspace attributes were particularly helpful; they could create a gap between an image and text that flows around it.
advertisement

8. What is longdesc attribute used for?
a) Displaying just the description of the image
b) Describing about the page in more detail
c) Indicate the URL of a document containing a description for the image in more detail
d) To provide a long description about the links present in the webpage
View Answer

Answer: c
Explanation: Sometimes images can contain a lot of information, in particular graphs and charts. By providing a long description of the image, not only are you helping search engines understand information that they would not otherwise be able to process, but you are also helping those users who cannot see the image (because of visual impairment).

9. Specifing a name for the image so that it can then be referenced from script code is done by ______
a) href
b) longdesc
c) desc
d) name
View Answer

Answer: d
Explanation: It is the predecessor to, and has been replaced by, the id attribute. The syntax for name attribute is name=”image_name”. Or the name usually gets its reference from the data filled in a form after submission.
advertisement

10. How to assign border to an image?
a) < img src=”logo.gif” alt=”Logo” border=”” / >
b) < img src=”images/logo.gif” alt=”Logo” border=”1” / >
c) < img src=”logo” alt=”Logo” border=”2” / >
d) < img src=”images/logo.gif” border=”3” / >
View Answer

Answer: b
Explanation: Images on their own do not have borders, you should be aware that Internet Explorer gives images a border when they are used as links. Commonly, border= ” 0 ” is used on images that are used inside links. This attribute has been replaced by the CSS border property.

Sanfoundry Global Education & Learning Series – Web Technology.

To practice all areas of Web Technology, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.