CSS MCQ

Welcome to the CSS Quiz for beginners! Test your foundational knowledge of Cascading Style Sheets (CSS) with these 35+ multiple-choice questions. Whether you’re just starting out or looking for a refresher, this quiz has got you covered.

Note that each question is followed by the correct answer and an explanation to help reinforce your knowledge.

1. What is the full form of the acronym CSS?

A. Cascading Style Sheets
B. Creative Style System
C. Computer Style Sheets
D. Cascading Simple System

Answer:

A. Cascading Style Sheets

Explanation:

CSS stands for Cascading Style Sheets. It's a styling language used to control the presentation of HTML documents.

2. Which property is used to change the text color of an element?

a) color
b) font-color
c) text-color
d) text

Answer:

a) color

Explanation:

The color property in CSS is used to change the text color of an element. You can specify colors using color names, hexadecimal values, RGB values, or HSL values.

3. Which HTML attribute is used to define inline styles?

a. class
b. font
c. style
d. styles

Answer:

c. style

Explanation:

The style attribute is used in HTML to define inline CSS.

4. Which of the following selectors targets all <p> elements?

A. #p
B. .p
C. p
D. *p

Answer:

C. p

Explanation:

In CSS, tag/element selectors are used without prefixes. So, "p" targets all <p> elements.

5. How do you set the background color of an element to red?

A. background-color = red;
B. background-color: red
C. color: red;
D. background: red;

Answer:

B. background-color: red

Explanation:

The property for setting the background color of an element is background-color.

6. Which property controls the font of an element?

A. text-style
B. text-font
C. font-style
D. font-family

Answer:

D. font-family

Explanation:

The font-family property specifies the font for an element.

7. How do you comment out multiple lines in CSS?

A. //This is a comment//
B. <!–This is a comment–>
C. /This is a comment/
D. –This is a comment–

Answer:

C. /This is a comment/

Explanation:

In CSS, multiple lines can be commented out using /* to start the comment and */ to end it.

8. Which property adds space inside an element?

A. margin
B. border
C. spacing
D. padding

Answer:

D. padding

Explanation:

Padding is used to create space around an element's content, inside of any defined borders.

9. Which of the following property is used to change the left margin of an element?

A. margin-left
B. padding-left
C. indent
D. left-margin

Answer:

A. margin-left

Explanation:

The margin-left property is used to set the left margin of an element.

10. How do you make all the letters in a text uppercase?

A. text-transform:uppercase;
B. text-style:uppercase;
C. font-case:uppercase;
D. text-case:uppercase;

Answer:

A. text-transform:uppercase;

Explanation:

The text-transform property controls text case and capitalization.

11. How do you select all elements with the class name "intro"?

A. .intro
B. intro
C. #intro
D. *intro

Answer:

A. .intro

Explanation:

In CSS, class selectors are prefixed with a dot (.). So, .intro will select all elements with the class name "intro".

12. How do you select an element with the ID "header"?

A. .header
B. header
C. *header
D. #header

Answer:

D. #header

Explanation:

In CSS, ID selectors are prefixed with a hash (#). So, #header will select the element with the ID "header".

13. Which property controls the text size?

A. text-size
B. font-size
C. text-style
D. font-weight

Answer:

B. font-size

Explanation:

The font-size property is used to control the size of the text.

14. How do you display hyperlinks without an underline?

A. a {decoration: none;}
B. a {text-decoration: none;}
C. a {underline: none;}
D. a {text-line: none;}

Answer:

B. a {text-decoration: none;}

Explanation:

The text-decoration property is used to set the decoration of the text. Setting it to none removes the underline from hyperlinks.

15. Which property aligns the text of an element to the center?

A. text-align: center;
B. text-center: true;
C. font-align: center;
D. align-text: center;

Answer:

A. text-align: center;

Explanation:

The text-align property is used to specify the horizontal alignment of text in an element.

16. Which property adds space between an element and its surrounding elements?

A. padding
B. margin
C. spacing
D. boundary

Answer:

B. margin

Explanation:

The margin property is used to create space around elements, outside of any defined borders.

17. What is the default value of the position property?

A. relative
B. absolute
C. fixed
D. static

Answer:

D. static

Explanation:

The default value of the position property is static, which means the element is not positioned in any special way.

18. Which of the following will hide an element by making it completely transparent but still occupying space?

A. visibility: invisible;
B. opacity: 0;
C. display: none;
D. color: transparent;

Answer:

B. opacity: 0;

Explanation:

Setting opacity to 0 will make an element completely transparent but still taking up space in the layout.

19. What is the purpose of the z-index property?

A. Specify the weight of a font
B. Set the zoom level of an element
C. Stack elements on the Z-axis
D. Determine the zig-zag pattern of borders

Answer:

C. Stack elements on the Z-axis

Explanation:

The z-index property specifies the stack order of an element. An element with a greater stack order is always in front of another element with a lower stack order.

20. Which value of the overflow property will cause scrollbars to always appear?

A. auto
B. hidden
C. scroll
D. visible

Answer:

C. scroll

Explanation:

Setting overflow to scroll will always display scrollbars, whether they're needed or not.

21. Which CSS property defines the space between the content of an element and its border?

A. margin
B. spacing
C. padding
D. border-spacing

Answer:

C. padding

Explanation:

Padding is the space between the content of an element and its border.

22. How do you specify a border for all four sides that is medium, dashed, and red?

A. border: red dashed medium;
B. border: medium dashed red;
C. all-border: medium dashed red;
D. border-all: red medium dashed;

Answer:

B. border: medium dashed red;

Explanation:

The shorthand border property allows you to set the width, style, and color of all four sides simultaneously.

23. How do you apply a class .selected to a <div> element in HTML?

A. <div class: "selected">
B. <div .selected>
C. <div class="selected">
D. <div id="selected">

Answer:

C. <div class="selected">

Explanation:

To apply a class to an element in HTML, you use the class attribute with the class name.

24. Which property adjusts the space between the individual characters of a text?

A. letter-spacing
B. word-spacing
C. text-spacing
D. font-spacing

Answer:

A. letter-spacing

Explanation:

The letter-spacing property adjusts the space between the characters of a text.

25. Which of the following is NOT a CSS framework?

A. Bootstrap
B. Angular
C. Bulma
D. Foundation

Answer:

B. Angular

Explanation:

Angular is a JavaScript framework for building web applications. It's not a CSS framework.

26. Which CSS property is used for specifying the shadows of a box?

A. shadow-box
B. border-shadow
C. box-shadow
D. padding-shadow

Answer:

C. box-shadow

Explanation:

The box-shadow property is used to add shadow effects around an element's frame.

27. Which of the following is a shorthand property for setting margin values in the order top, right, bottom, left?

A. margin: 10px 20px 10px 20px;
B. margin: 10px 10px 20px 20px;
C. margin: 20px 10px 10px 20px;
D. margin: 10px 20px 20px 10px;

Answer:

A. margin: 10px 20px 10px 20px;

Explanation:

The margin shorthand follows the sequence: top, right, bottom, left.

28. What will flex: 1 do in a flex container?

A. Makes the item flexible and sets the flex item's width to 1px
B. Sets the flex-grow property to 1, allowing it to grow if necessary
C. Forces the item to be the first in the display order
D. Aligns the item to the start of the flex container

Answer:

B. Sets the flex-grow property to 1, allowing it to grow if necessary

Explanation:

flex: 1 is shorthand that specifies the ability of a flex item to grow if necessary. It's equivalent to setting flex-grow: 1.

29. How do you add a background color for all <ul> elements?

A. ul all {background-color: #EDEDED;}
B. ul {background-color: #EDEDED;}
C. all.ul {background-color: #EDEDED;}
D. list ul {background-color: #EDEDED;}

Answer:

B. ul {background-color: #EDEDED;}

Explanation:

You can directly use the element's name as the selector to style it.

30. Which of the following properties will not affect an inline element?

A. color
B. padding
C. width
D. font-size

Answer:

C. width

Explanation:

Inline elements do not respect the width and height properties, they wrap content and don’t force line breaks.

31. How can you add a comment in a CSS file?

A. // this is a comment
B. <!– this is a comment –>
C. /* this is a comment */
D. — this is a comment —

Answer:

C. /* this is a comment */

Explanation:

In CSS, comments are added by wrapping the text between /* and */.

32. Which property is used to add a background image?

a. background-color
b. color
c. background-image
d. image-background

Answer:

c. background-image

Explanation:

The background-image property is used to specify a background image.

33. Which property is used to create rounded corners for an element?

a) border-style
b) border-radius
c) border-width
d) border-color

Answer:

b) border-radius

Explanation:

The border-radius property in CSS is used to create rounded corners for an element's border. You can specify a single value for all corners or individual values for each corner.

34. What is the purpose of the display: none; property in CSS?

a) It hides an element without affecting the layout.
b) It removes the element from the DOM.
c) It creates an invisible element that still occupies space.
d) It applies an invisible background color to the element.

Answer:

a) It hides an element without affecting the layout.

Explanation:

The display: none; property in CSS hides an element from the layout, making it effectively invisible. However, it still occupies space in the document flow.

35. What is the purpose of the float property in CSS?

a) It controls the vertical alignment of an element.
b) It allows text to wrap around an element.
c) It animates an element's position.
d) It applies a blur effect to an element.

Answer:

b) It allows text to wrap around an element.

Explanation:

The float property in CSS is used to allow text and other inline elements to wrap around a floated element, such as an image.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top