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. The full form of CSS is:
A Cascading Style Sheets
B Coloured Special Sheets
C Color and Style Sheets
D None of these answers
A
CSS stands for Cascading Style Sheets.
2. How do you change the background color of an element?
A background-color
B color
C Both A and B
D None of these answers
A
The background-color property allows you to change the background color of an element. Example to set the background color of a page:
body {background-color: blue;}
3. How many ways can you write CSS?
A 1
B 2
C 3
D 4
C
CSS style sheets can be added to HTML documents in three ways:
Inline – using the style attribute inside HTML elements. Example: <p style="color:red;">A red paragraph.</p>
Internal – using the <style> element in the <head> section. Example:
<html>
<head>
<style>
p {color: red;}
</style>
</head>
<body>
<p>A red paragraph.</p>
</body>
</html>
External – using the <link> element to link to an external CSS file. Example:
4. What type of CSS is used in the following code snippet?
<h1 style="color:blue;">A blue title</h1>
A Inline
B Internal
C External
D None of these answers
A
The code above is an example of Inline CSS.
5. What type of CSS is generally recommended for designing large web pages?
A Inline
B Internal
C External
D None of these answers
C
The advantages of using an external style sheet include: everything is stored in one file. Once modified/updated, changes are reflected across all other pages referencing the style sheet. This makes it easier to maintain large websites.
6. Which HTML tag is used to declare internal CSS?
A <link>
B <style>
C <script>
D <css>
B
The HTML tag <style> is used to declare internal CSS style sheets. Example:
<html>
<head>
<style>
p {color: red;}
</style>
</head>
<body>
<p>A red paragraph.</p>
</body>
</html>
7. How do you select an element with a specific ID in CSS?
A #
B .
C ^
D +
A
ID’s are selected in CSS using # followed by the ID name. For example, the following CSS rule will be applied to the HTML element with id="para1":
8. How do you select an element with a specific class in CSS?
A #
B .
C ^
D +
B
Classes are selected in CSS using . followed by the class name. For example, the following CSS rule selects and styles all elements with class="intro":
.intro {
background-color: blue;
}
9. In the code snippet below, in what order will the margins be added?
p { margin: 25px 50px 75px 100px;}
A Top, Right, Bottom, Left
B Top, Left, Bottom, Right
C Top, Bottom, Right, Left
D Right, Left, Top, Bottom
A
The CSS margin property has four directions: top, right, bottom, and left. In the example above, the margin property has four values:
top margin is 25px
right margin is 50px
bottom margin is 75px
left margin is 100px
10. Can negative values be allowed in the “padding” property?
A Yes
B No
C Depends on the property
D None of these answers
B
No. Padding only accepts positive values. Negative values are ignored or treated as 0, which would have the same effect as: none. Margins can accept negative values, as can other positioning-related properties, but not padding.
MCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More