HTML/CSS MCQ

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

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 a <div> element to occupy 50% of its parent container’s width, which CSS property would you use?

A width: 50%;

B height: 50%;

C max-width: 50%;

D size: 50%;

A
The width property defines the width of an element. Setting it to 50% makes the element take up half the width of its parent.
 

2. What does the CSS property float: right; do?

A Moves an element to the right and makes it float above other elements

B Moves an element to the left and makes it float

C Moves an element to the right without floating it

D Moves an element to the right and prevents other elements from touching it

A
The float property moves an element to the left or right. Using float: right; makes the element float to the right and allows other content to wrap around it.
 

3. Which CSS property creates a border around an element with rounded corners?

A rounded-border

B border-style

C corner-radius

D border-radius

D
The border-radius property adds rounded corners to an element. For example: border-radius: 10px;.
 
 

4. What does the following CSS code do?
#box {
  margin: auto;
  width: 50%;
}

A Horizontally centers the element

B Vertically centers the element

C Applies a 50% width without changing position

D Centers the element both vertically and horizontally

A
margin: auto; horizontally centers an element within its container if a width is defined, like here at 50%. It does not affect vertical position.
 

5. What does the following CSS rule do?
#box {
  position: absolute;
  top: 20px;
  left: 50px;
}

A Positions the element relative to its immediate parent

B Fixes the element to the top-left corner of the window

C Positions the element 20px from the top and 50px from the left of the page

D Creates a floating effect in the top left

C
position: absolute; positions an element relative to the closest positioned ancestor, or the page if none exists. top and left define the offsets.
 

6. What does the following code do?
#button:hover {
  background-color: green;
  color: white;
  cursor: pointer;
  transform: scale(1.2);
}

A Changes text color on hover

B Changes the button size on hover

C Changes background and text color and enlarges on hover

D Changes the button color to green without hover effect

C
The :hover selector applies style changes when hovering over an element. Here, the background turns green, text turns white, and the size increases by 1.2x via transform: scale(1.2).
 
 

7. Which CSS property adds a blur effect to an element’s background?

A background-blur

B filter: blur;

C backdrop-filter: blur;

D blur-effect: true;

C
The backdrop-filter property applies graphic effects like blur to the background behind an element, while keeping the element’s content clear. Example: backdrop-filter: blur(10px);.
 

8. If you want an image to take up the full width of the screen while maintaining its aspect ratio, which CSS rule should you use?

A width: 100%; height: auto;

B width: auto; height: 100%;

C max-width: 100%;

D height: 100%; width: auto;

A
width: 100% ensures the image stretches to full width, and height: auto; maintains the aspect ratio.
 

9. What’s the main difference between position: relative; and position: absolute;?

A relative places the element at the bottom of its container; absolute places it relative to the window

B relative positions the element relative to its original location; absolute positions it relative to its first positioned parent

C They do the same thing, but absolute is faster

D relative places an element on top of others; absolute hides it behind

B
position: relative; offsets an element from its original position. position: absolute; positions the element relative to its nearest positioned ancestor.
 
 

10. What does the CSS property clamp() do?

A Sets a responsive size between a minimum and maximum value depending on screen size.

B Applies a blur effect based on size range.

C Defines a dynamic transform effect.

D Clips content to fit the parent’s size.

A
clamp() is a CSS function that sets a value between a defined minimum and maximum. For example, clamp(200px, 10vw, 400px); makes the size responsive from 200px to 400px based on viewport width.
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 *