HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 56
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 all <input> elements that have a defined (non-empty) value?
A input:not(:empty) {}
B input[value] {}
C input[value!=""] {}
D input:not(:blank) {}
2. Which selector targets the first <li> element in a list group that is also a <strong> element?
A ul > li:first-child strong {}
B ul > li:first-of-type strong {}
C ul > li:first-child:strong {}
D ul > li > strong:first-child {}
3. Which CSS selector targets a <span> element that contains exactly three words (using spaces as separators)?
A span:contains("word word word") {}
B span:words(3) {}
C span { word-count: 3; }
D This selector does not exist in pure CSS.
4. Which CSS selector targets an <input> element whose value is exactly “email” (case-sensitive)?
A input[value="email"] {}
B input[value="email"]:exact {}
C input[value="email"] {}
D input[value~="email"] {}
5. Which selector targets all <h1>, <h2>, and <h3> elements that are within a <header> container?
A header h1, header h2, header h3 {}
B header > h1, h2, h3 {}
C header:h1, header:h2, header:h3 {}
D h1, h2, h3 > header {}
6. Which CSS selector targets all <li> elements that do not contain an <a> element inside?
A li:has(:not(a)) {}
B li:not(a) {}
C li:empty {}
D li:not(:has(a)) {}
7. Which CSS selector targets all <p> elements that are immediately followed by a <footer> element?
A p + footer {}
B footer + p {}
C p ~ footer {}
D footer ~ p {}
8. Which CSS selector targets a <input> element of type text when its content is empty?
A input[type="text"]:empty {}
B input[type="text"]:not(:empty) {}
C input[type="text"]:value="" {}
D input[type="text"]:placeholder-shown {}
9. Which selector targets a <p> element within a <div> whose text is bold?
A div p { font-weight: bold; }
B div p:font-weight(bold) {}
C div p b {}
D div > p:has(b) {}
10. Which CSS selector targets all <span> elements inside a <p>, but only within the last paragraph on the page?
A p:last-of-type span {}
B p span:last-child {}
C p:last-child span {}
D p span:last-of-type {}