HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 49
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. If you want to create a section where the content can be edited in real-time by the user, which tag would be most appropriate?
A <div contenteditable="true">
B <input type="text">
C <textarea>
D <editable>
2. What is the main difference between the <strong>
and <b>
tags?
A None, they are two identical tags.
B <strong>
indicates strong importance, while <b>
just makes text bold.
C <strong>
is used for links and <b>
for images.
D <strong>
makes text italic and <b>
makes it bold.
3. You want to apply a style to all <section> elements that contain at least one <h3> element. Which CSS selector would you use?
A section > h3
B section h3
C section:has(h3)
D section h3 + section
4. Suppose you want to target all <h1> elements on a page, but only if each <h1> is preceded by a <p> element containing specific text. Which selector would you use?
A p:contains("text") + h1
B p + h1:contains("text")
C h1:preceding(p:contains("text"))
D p:contains("text") ~ h1
5. You have a list of products with <div> elements, but you want to target only the second <div> in a series of sibling elements. Which CSS selector would you use?
A div:nth-child(2)
B div:nth-of-type(2)
C div:first-child + div
D div + div:nth-child(2)
6. You want to apply a style to all <li> elements in a list, but only those that are in odd positions (1st, 3rd, 5th, etc.). Which CSS selector would you use?
A li:nth-child(odd)
B li:nth-of-type(odd)
C li:nth-child(2n+1)
D li:nth-child(2n)
7. What is the main difference between the <div> and <section> tags?
A <div> is a generic container with no semantic meaning, while <section> marks a thematic section of content with semantic meaning.
B <div> is only used for images, while <section> is for text.
C <div> is an interactive tag, while <section> is static.
D There’s no difference; both tags do exactly the same thing.
8. You have several buttons on a page with the class .btn, and some have a disabled attribute. You want to target all disabled buttons that have the .btn class. Which CSS selector would you use?
A .btn:disabled
B .btn[disabled]
C button.btn:disabled
D button:disabled.btn
9. You want to apply a style to all <h2> elements that are immediately followed by a <p> element. Which CSS selector would you use?
A h2 + p
B h2 > p
C h2 ~ p
D h2 + p:after
10. You want to target all <div> elements that contain only one <span> element inside. Which CSS selector would you use?
A div:has(span)
B div > span
C div > span:only-child
D div:only-child span