HTML/CSS MCQ

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

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. What does the following CSS code do?
.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

A Creates a grid with three equal columns

B Creates a grid with three columns of variable sizes

C Creates a grid with a single column

D Creates a grid with two columns

A
The rule grid-template-columns: repeat(3, 1fr); creates a grid of three equal-sized columns, where 1fr represents a fraction of the available space.
 

2. What is the purpose of the rel="noopener noreferrer" attribute in a <a> link?

A It prevents the link from opening in a new window

B It improves security by preventing the linked page from accessing the origin page

C It forces the link to be unclickable

D It adds a custom style to the link

B
The rel="noopener noreferrer" attribute is used to secure links that open in a new window (target="_blank") by preventing the linked page from accessing the origin page via JavaScript.
 

3. How can you make text get cut off and replaced with ellipsis when there is not enough space?

A text-overflow: ellipsis;

B text-clamp: ellipsis;

C overflow-text: ellipsis;

D clipping-text: ellipsis;

A
The text-overflow: ellipsis; property cuts off the text when it overflows a container and replaces the end with ellipsis (…). This works with overflow: hidden; and white-space: nowrap;. See a complete example.
 
 

4. What is the difference between ‘rem’ and ’em’ in CSS?

A rem is relative to the window size, em is relative to the parent text size

B rem is relative to the parent text size, em is relative to the window size

C rem is a fixed unit, em is relative to the default font size

D No difference, they are identical

A
rem (root em) is relative to the font size of the root element (html), while em is relative to the font size of the immediate parent element.
 

5. Which CSS method is used to center an element both horizontally and vertically within a container?

A center: both;

B text-align: center; vertical-align: middle;

C display: flex; justify-content: center; align-items: center;

D position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);

C
Using display: flex, justify-content: center centers the element horizontally, and align-items: center centers it vertically. This approach is very popular in modern layouts.
 

6. What does the CSS property box-sizing: border-box; do?

A Changes the size of elements by including border and padding in the total width and height

B Changes the border color of elements

C Applies a colored background to elements

D Resizes the content box without affecting the text

A
box-sizing: border-box; changes the way the width and height of elements are calculated by including padding and border in the specified dimensions.
 
 

7. What does the following CSS rule do?
#header {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

A Creates a grid of three rows with variable heights, where the first and last are auto-sized, and the second takes up the remaining space

B Creates a grid with a single row

C Creates a grid with two rows, the second being larger

D Creates a grid container with no rows

A
grid-template-rows: auto 1fr auto; defines three rows: the first and last have automatic height, while the middle row takes up all remaining space (1fr).
 

8. What is the effect of the white-space: nowrap; property in CSS?

A Forces text to display on multiple lines

B Prevents text lines from breaking, forcing all text to display on a single line

C Aligns text to the left

D Prevents elements from resizing

B
white-space: nowrap; prevents text from breaking into multiple lines, forcing the text to stay on a single line, which can cause overflow if space is insufficient.
 

9. Which CSS property is used to create a circular (radial) gradient effect on an element?

A background-image: radial-gradient(circle, red, yellow);

B background: radial-gradient(circle, red, yellow);

C background-image: gradient-radial(red, yellow);

D background-color: radial-gradient;

A
The correct syntax for a radial gradient is background-image: radial-gradient(circle, red, yellow);. This creates a circular gradient that starts with red and ends with yellow. See a complete example.
 
 

10. What does the clip-path: circle(50%); property do?

A Masks part of the element with a circular shape

B Cuts the element into two equal parts

C Creates a circular border around the element

D Applies a circular shadow to the element

A
clip-path: circle(50%); allows you to crop an element into a circular shape by hiding the parts that extend beyond the circle. The element becomes visible only in that shape.
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 *