HTML/CSS MCQ

HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 25

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 define a navigation bar?

A <nav>

B <menu>

C <footer>

D <header>

A
The <nav> tag is used to define a navigation section, typically containing links to other pages or sections of the site. Example:

<nav>
    <a href="#home">Home</a>
    <a href="#about">About</a>
    <a href="#contact">Contact</a>
</nav>
 

2. How do you apply a CSS style to all <p> elements in an HTML file?

A p { color: blue; }

B p[style] { color: blue; }

C all p { color: blue; }

D p > { color: blue; }

A
The CSS selector p targets all <p> elements in an HTML document. The syntax p { color: blue; } applies a blue color to all paragraphs.
 

3. What is the effect of the CSS property display: none;?

A The element becomes invisible but still occupies space on the page

B The element is completely hidden and occupies no space

C The element becomes invisible but remains interactive

D The element becomes opaque

B
The display: none; property hides an element completely—it’s not visible and does not take up space. This differs from visibility: hidden;, which hides the element but keeps its space.
 
 

4. Which HTML attribute is used to add a caption to a table?

A <legend>

B <caption>

C <title>

D <header>

B
The <caption> tag is used to add a title or description to an HTML table. It must be placed directly after the <table> tag. For example:

<table>
    <caption>Product List</caption>
    <tr><td>Product 1</td></tr>
    <tr><td>Product 2</td></tr>
</table>
 

5. Which CSS property is used to set the height of an element?

A width

B height

C size

D box-height

B
The height property in CSS is used to set the height of an element. It can be defined using pixels, percentages, or other units.
 

6. What is the effect of the CSS float property?

A It sets the element’s position relative to its parent.

B It allows an element to float left or right inside its container, letting content flow around it.

C It removes the element from the normal document flow.

D It adjusts the element’s width.

B
The float property allows an element to float to the left or right of its container so that other content wraps around it. This is often used for layout columns. See a complete example.
 
 

7. Which CSS property adjusts the spacing between words?

A letter-spacing

B word-spacing

C line-height

D text-spacing

B
The word-spacing property adjusts the space between words in text. Example: word-spacing: 5px;. See a complete example.
 

8. Which CSS property defines how floating elements behave around other content?

A clear

B float

C position

D display

A
The clear property specifies whether an element can be positioned beside or after floating elements. For example, clear: both; prevents floating on both sides.
 

9. Which CSS property allows an element’s size to adjust based on its content?

A height

B min-height

C max-height

D auto

D
In CSS, auto lets the size of an element adjust automatically based on its content. It’s often used with width or height properties.
 
 

10. Which CSS property displays an element as a block, taking up the full available width?

A display: block

B display: inline

C display: inline-block

D display: none

A
The display: block property displays an element as a block-level element, meaning it will take up the full width of its container, and elements after it will appear on a new line. See a complete example.
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 *