HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 48
Multiple choice questions and answers (MCQs) on HTML/CSS to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as tags, web standards, CSS selector, objects, and more. This quiz will easily prepare anyone to pass their online test.
1. Which HTML tag is used to add a date and time in a structured format?
A <date>
B <time>
C <datetime>
D <timestamp>
2. Which tag is used to display an image as a background of an HTML element?
A <background>
B <image>
C <style>
D <div style="background-image:url('image.jpg')">
3. You have a <div> section containing both <p>, <h2>, and <span> elements. You want to target all <h2> elements, but only those that are preceded by a <p> within the same parent <div>. Which CSS selector would you use?
A div > p + h2
B div p + h2
C div h2 ~ p
D div > h2:preceding(p)
4. You want to apply a style only to <div> elements that are hidden, using the attribute aria-hidden="true"
. Which CSS selector would you use?
A div[aria-hidden="true"]
B div[hidden]
C div:aria-hidden(true)
D div:not([aria-hidden="false"])
5. You want to target only visible elements within a container, excluding elements with display: none
or visibility: hidden
. What is the most appropriate CSS selector?
A div:visible
B div:not([hidden])
C div:visible:not([display="none"])
D There is no CSS selector for this
6. You want to target all <a> links on your page, but only those that have been clicked and are currently active. Which selector would you use?
A a:focus:active
B a:visited:active
C a:active
D a:visited:focus
7. You want to target all <li> elements in a list, but only those in even positions and that contain a <span> child. Which CSS selector would you use?
A li:nth-child(even) > span
B li:nth-child(even):has(span)
C li:even > span
D li:nth-child(2n):has(span)
8. Imagine a page structure with several <section> elements, and you want to apply a style to all <p> elements inside a section with the class .highlighted
. Which selector would you use?
A .highlighted p
B section p.highlighted
C .highlighted > p
D .highlighted :p
9. You want to apply a style only to <h2> elements that are preceded by two <p> elements, in a page structure where each <h2> may be preceded by different types of elements. Which selector would you use?
A p + p + h2
B p ~ p + h2
C p > p + h2
D h2:preceding(p + p)
10. You want to apply a style to a <p> element only if its parent is a <div> with the class “container”. Which CSS selector would you use?
A div.container > p
B div > .container p
C .container p
D div p.container