HTML/CSS MCQ

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 {}

A
The selector ol li {} selects all <li> elements that are children (at any level) of an <ol> element, i.e., all items in the ordered list.
 

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 {}

A
The selector p:not(:first-child) {} targets all <p> elements that are not the first child of a parent. The :not() pseudo-class excludes a specific case, here :first-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 {}

A
The selector input[type="radio"]:checked {} selects all <input> elements of type radio that are checked. The :checked pseudo-class is used to target selected elements (like checkboxes or radio buttons).
 
 

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.

D
There is no CSS selector based on the font-style property (or any other style property) applied to content. CSS selectors are based on the HTML structure, not applied styles.
 

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) {}

C
The selector p:not(:has(+ p)) targets all <p> elements that are not immediately followed by another <p>. The :has() pseudo-class allows you to select an element based on what comes after it.
 

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"] {}

A
The selector a[href*="example.com"] selects all <a> elements whose href attribute contains “example.com”. The * is used to indicate that the value may appear anywhere in the URL.
 
 

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"] {}

A
The selector div[data-color="red"].highlight selects <div> elements that have both the data-color="red" attribute and the highlight class. You can combine multiple selectors like this for more specificity.
 

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 {}

A
The selector input[type="checkbox"]:not(:checked) selects all <input> checkbox elements that are not checked. The :not(:checked) pseudo-class excludes checked boxes.
 

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] {}

B
The selector .gallery img[width > 200px] targets <img> elements inside the .gallery class whose width attribute is greater than 200px. It’s an attribute selector combined with a comparison condition.
 
 

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 {}

C
The selector button:focus targets all buttons when they receive focus, whether by click or keyboard navigation (like Tab). It’s commonly used to style keyboard-active elements.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *