css banner

CSS Multiple Choice Questions (MCQs) and Answers

Master CSS with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of CSS. Begin your placement preparation journey now!

Q1

Q1 What is the primary purpose of CSS in web development?

A

To create web pages

B

To style web pages

C

To store data

D

To program web applications

Q2

Q2 Which of the following is a valid way to integrate CSS into a webpage?

A

Inline

B

External

C

Internal

D

All of the above

Q3

Q3 Which CSS property is used to change the text color of an element?

A

text-color

B

color

C

font-color

D

background-color

Q4

Q4 Given the following CSS, what color will the <h1> text be?

body { color: red; } h1 { color: blue; }

A

Red

B

Blue

C

Green

D

Black

Q5

Q5 Which selector is used to target an element based on its id?

A

#id

B

.id

C

*id

D

id

Q6

Q6 What does the universal selector (*) do in CSS?

A

Targets all elements in a document

B

Targets no elements

C

Targets the body element

D

Targets elements with a specific id

Q7

Q7 Which property is used to set the background color of an element?

A

color

B

background-color

C

bgcolor

D

background

Q8

Q8 How do you select elements with the class name "example"?

A

.example

B

#example

C

example

D

*example

Q9

Q9 What is the correct syntax to select all <p> elements inside <div> elements?

A

div p

B

div + p

C

div > p

D

p > div

Q10

Q10 Which of the following is true about the CSS selector div.example?

A

Selects all divs with the class "example"

B

Selects the first div with the class "example"

C

Selects all divs

D

Selects all elements with the class "example"

Q11

Q11 What will be the font size of <p class="text">Hello World!</p> with the CSS .text { font-size: 20px; }?

A

15px

B

20px

C

25px

D

30px

Q12

Q12 Given the CSS div > p { color: red; }, what color will the text be in <div><p>Hello</p></div>?

A

Red

B

Blue

C

Green

D

Black

Q13

Q13 Identify the error in the CSS code:
.class { color: blue; font-weight; bold; }

A

Syntax error in property declaration

B

Missing class name

C

Incorrect property value

D

No error

Q14

Q14 Why might the CSS rule .container p { color: green; } not apply to a paragraph inside a div with class "container"?

A

The div does not have the "container" class

B

The paragraph is not a direct child

C

There is a more specific rule overriding this one

D

The CSS file is not linked properly

Q15

Q15 What components make up the CSS Box Model?

A

Content, Padding, Border, Margin

B

Padding, Margin, Border, Shadow

C

Content, Margin, Border, Outline

D

Content, Padding, Shadow, Margin

Q16

Q16 Which property is used to set the space between the border of an element and its content?

A

Margin

B

Padding

C

Border

D

Outline

Q17

Q17 What does the 'box-sizing' property do?

A

Changes the CSS Box Model calculation

B

Alters the display property

C

Adjusts the border thickness

D

Modifies the margin size

Q18

Q18 Which CSS property is used to control the outer space around an element?

A

Padding

B

Margin

C

Border

D

Content

Q19

Q19 How can you make the total width of an element be 100px including padding and border?

A

Use 'box-sizing: border-box;' with width set to 100px

B

Set width to 100px without 'box-sizing' property

C

Use 'box-sizing: content-box;' with width set to 100px

D

Set width, padding, and border so their sum is 100px

Q20

Q20 What is the default value of the 'box-sizing' property?

A

content-box

B

border-box

C

padding-box

D

margin-box

Q21

Q21 Which property would you use to create space between elements?

A

Padding

B

Margin

C

Border

D

Outline

Q22

Q22 If an element has a width of 100px, padding of 10px, and border of 5px, what is the total width of the element if 'box-sizing' is set to 'border-box'?

A

100px

B

120px

C

130px

D

150px

Q23

Q23 How does setting 'margin: auto;' affect an element?

A

Centers the element horizontally

B

Increases the element's height

C

Adds automatic padding

D

Does nothing specific

Q24

Q24 Given an element with padding: 20px; and width: 200px;,
what is the total width of the element?

A

200px

B

220px

C

240px

D

260px

Q25

Q25 What is the effect of setting margin: 0 auto; on an element?

A

It removes the element's margins

B

It centers the element horizontally

C

It sets the margin on all sides to auto

D

It increases the margin size

Q26

Q26 If an element has margin: 10px; and padding: 20px;,
what is the space between the element and its neighboring element?

A

10px

B

20px

C

30px

D

40px

Q27

Q27 An element has width: 100px; padding: 15px; border: 5px solid black;.
What is its total width if box-sizing: content-box;?

A

100px

B

115px

C

130px

D

150px

Q28

Q28 Identify the issue: div { width: 100%; padding: 20px; } without using box-sizing: border-box;.

A

The div will be wider than its parent

B

The div's width is too small

C

No issue

D

The padding is ignored

Q29

Q29 What is the problem with using margin: 0 auto; on an inline element?

A

Inline elements cannot be centered this way

B

The margin will collapse

C

The auto value is invalid for inline elements

D

No issue

Q30

Q30 A block element inside a container does not respect the specified margin-top. What could be the reason?

A

Margin collapse

B

Incorrect box-sizing

C

Border interference

D

Padding on the container

...
ad verticalad vertical
ad