HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 55
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 CSS selector targets <li> elements that are list items within an ordered list (<ol>)?
A ol li {}
B ol > li {}
C li:ol {}
D ol + li {}
2. Which CSS selector targets all <p> elements that are not the first child of a parent?
A p:not(:first-child) {}
B p:not(:last-child) {}
C p:first-child {}
D p:last-child {}
3. Which CSS selector selects all <input> radio elements that are checked?
A input[type="radio"]:checked {}
B input:checked[type="radio"] {}
C input:radio:checked {}
D input[type="radio"]:active {}
4. Which CSS selector targets an element only if its text is italicized (using font-style: italic
)?
A p:italic {}
B p[font-style="italic"] {}
C p::italic {}
D This selector does not exist.
5. Which CSS selector targets all <p> elements that are not followed by another <p> element?
A p:only-child {}
B p:empty {}
C p:not(:has(+ p)) {}
D p:not(:last-child) {}
6. Which selector targets all <a> elements pointing to a URL that contains example.com?
A a[href*="example.com"] {}
B a[href="example.com"] {}
C a[href^="example.com"] {}
D a[href$="example.com"] {}
7. Which CSS selector targets a <div> element with a data-color="red"
attribute and a highlight
class?
A div[data-color="red"].highlight {}
B div.highlight[data-color="red"] {}
C div[data-color="red"]:highlight {}
D div.highlight[data-color="red"] {}
8. Which CSS selector targets a <input> element of type checkbox only if it is unchecked?
A input[type="checkbox"]:not(:checked) {}
B input[type="checkbox"]:checked {}
C input[type="checkbox"]:active {}
D input[type="checkbox"]:focus {}
9. Which selector selects all <img> elements inside a container with the class gallery and a width greater than 200px?
A .gallery img { width: 200px; }
B .gallery img[width > 200px] {}
C .gallery img[width="200"] {}
D .gallery img[width] {}
10. Which CSS selector targets all <button> elements that have been activated via a keyboard key (focus)?
A button:focus-within {}
B button:active {}
C button:focus {}
D button:focus-visible {}