Practice Questions, Introduction to CSS - Styling the Web
← Back to NotesTopic-Specific Questions
Question 1
Easy
What does CSS stand for?
It describes how styles flow.
Cascading Style Sheets
Question 2
Easy
What symbol separates a CSS property from its value?
Not an equal sign.
A colon
:Question 3
Easy
What symbol ends a CSS property declaration?
Not a period.
A semicolon
;Question 4
Easy
Write a CSS rule that makes all paragraphs blue.
Use the p selector and the color property.
p {
color: blue;
}Question 5
Easy
Which is the best practice for adding CSS to a website: inline, internal, or external?
The one that separates concerns best.
External CSS (a separate .css file linked with
<link>).Question 6
Easy
Write the HTML tag to link an external CSS file called 'main.css'.
Use the link tag.
<link rel="stylesheet" href="main.css">Question 7
Easy
Where do you put internal CSS in an HTML file?
Inside a specific tag in the head.
Inside a
<style> tag inside the <head> section.Question 8
Easy
Style this HTML so it has a blue background and white text. Use internal CSS.
<h1>Hello</h1>
<p>Welcome</p>Use body selector for the background.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: blue;
color: white;
}
</style>
</head>
<body>
<h1>Hello</h1>
<p>Welcome</p>
</body>
</html>Question 9
Easy
Which attribute is used for inline CSS?
It goes directly on an HTML tag.
styleQuestion 10
Easy
What is wrong with this CSS?
h1 {
color = red;
}CSS uses a different symbol.
CSS uses a colon
:, not an equal sign =. Correct: color: red;Question 11
Easy
Write an inline CSS rule to make an h1 red and centered.
Use the style attribute.
<h1 style="color: red; text-align: center;">My Heading</h1>Question 12
Easy
How do you write a CSS comment?
Not like HTML.
/* comment here */Question 13
Easy
Create a CSS rule that makes all links (a tags) have no underline.
Use text-decoration: none.
a {
text-decoration: none;
}Question 14
Easy
What does this CSS do?
body {
font-family: Arial;
}Applies to the entire body.
Sets the font of the entire page to Arial.
Question 15
Easy
Why does this CSS not work?
p
color: blue;
font-size: 20px;Something is missing.
Missing curly braces
{ }. Properties must be inside braces.Question 16
Medium
Create a complete HTML page with internal CSS that has a yellow background and red heading.
Use style tag in head with body and h1 selectors.
<!DOCTYPE html>
<html>
<head>
<style>
body { background-color: yellow; }
h1 { color: red; }
</style>
</head>
<body>
<h1>Hello</h1>
</body>
</html>Question 17
Medium
Which of these wins when multiple rules apply to the same element: inline, internal, or external CSS (same specificity)?
The closest to the element wins.
Inline CSS wins (highest specificity).
Question 18
Medium
Write a CSS rule that styles h1, h2, and h3 all in dark green.
Use a comma to group selectors.
h1, h2, h3 {
color: darkgreen;
}Question 19
Medium
In the cascade, which has higher specificity:
.red or p?Classes beat elements.
.red (class) has higher specificity than p (element).Question 20
Medium
Aarav linked his CSS but it does not apply. Why?
<!-- index.html -->
<head>
<link href="style.css">
</head>Missing an attribute.
Missing
rel="stylesheet". The browser does not know it is a stylesheet.Question 21
Medium
Style a complete HTML page: background should be light blue, headings dark blue and centered, paragraphs in Arial font and grey color.
Body for background, h1 for headings, p for paragraphs.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
font-family: Arial;
}
h1 {
color: darkblue;
text-align: center;
}
p {
color: grey;
}
</style>
</head>
<body>
<h1>Priya's Page</h1>
<p>Welcome!</p>
</body>
</html>Question 22
Medium
What specificity does an inline style have?
It is the highest.
1000 (the highest).
Question 23
Hard
Write a complete HTML page that uses external CSS. Include both the HTML file content and what should go in style.css.
Two files: index.html links to style.css.
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Welcome</h1>
<p>Styled with external CSS!</p>
</body>
</html>
/* style.css */
body {
background-color: #f0f0f0;
font-family: Arial;
}
h1 { color: purple; }
p { color: darkgreen; }Question 24
Hard
If
p { color: red; } is in external CSS and p { color: blue; } is in internal CSS below it, which color wins?Internal CSS comes later.
Blue wins. When specificity is the same, later rules override earlier ones.
Question 25
Hard
Why does the font-size not apply?
p {
color: red
font-size: 20px;
}Check for missing punctuation.
Missing semicolon after
red. Without it, the parser breaks and ignores everything after.Question 26
Hard
Build a page with 3 different sources of CSS rules that conflict: external rule makes p blue, internal makes p red, inline makes p green. Which color will the paragraph show?
Inline has the highest specificity.
<!-- Paragraph shows GREEN because inline wins -->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="external.css"> /* p { color: blue; } */
<style>
p { color: red; }
</style>
</head>
<body>
<p style="color: green;">Hello</p>
</body>
</html>Mixed & Application Questions
Question 1
Easy
What is the file extension for CSS files?
Short abbreviation.
.cssQuestion 2
Easy
Write a CSS rule for a div that has a red background and 20px of padding.
Use div as the selector.
div {
background-color: red;
padding: 20px;
}Question 3
Easy
Which goes inside the
<head>: the <style> tag or the <link> tag for CSS?Both, actually.
Both.
<style> for internal CSS and <link> for external CSS.Question 4
Easy
What is wrong?
<p style=color: red;>Hi</p>Missing quotes.
The style attribute value must be in quotes:
style="color: red;"Question 5
Easy
Write CSS to make h1 elements 40 pixels tall (font size).
Use font-size.
h1 {
font-size: 40px;
}Question 6
Medium
True or false: CSS comments and HTML comments use the same syntax.
They are different.
False. CSS uses
/* */, HTML uses <!-- -->.Question 7
Medium
Create a CSS rule that uses a comment explaining what the rule does, then sets the body background to light yellow.
Use /* comment */ before the rule.
/* Set the page background to light yellow */
body {
background-color: lightyellow;
}Question 8
Medium
What happens if you write CSS with
background: red but forget the semicolon?The next rule might not work.
This single rule works (the last rule in a block does not strictly need a semicolon), but if you add another line after, it will break. Always use semicolons.
Question 9
Medium
The CSS file is in a folder called 'assets/css/'. What should the href be?
Include the folder path.
<link rel="stylesheet" href="assets/css/style.css">Question 10
Medium
Write a complete HTML page with a gradient-like feel: dark background, bright pink heading, white paragraph text. Use internal CSS.
Body background dark, h1 pink, p white.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #1a1a2e;
color: white;
font-family: Arial;
padding: 30px;
}
h1 {
color: #ff4081;
text-align: center;
}
</style>
</head>
<body>
<h1>Welcome!</h1>
<p>This is my cool styled page.</p>
</body>
</html>Question 11
Hard
In a CSS rule
#main { color: red; }, what is the specificity?IDs have specificity 100.
100 (because #main is an ID selector).
Question 12
Hard
Write a complete HTML page linked to an external CSS file. Include both file contents. Style should make body dark, h1 yellow, and paragraphs light grey.
Remember the link tag in HTML.
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Welcome</h1>
<p>External CSS rocks!</p>
</body>
</html>
/* style.css */
body {
background-color: #1a1a2e;
font-family: Arial;
}
h1 {
color: yellow;
text-align: center;
}
p {
color: lightgrey;
}Question 13
Hard
Given
.highlight { color: red; } and p { color: blue; }, what color is <p class="highlight">Text</p>?Class has higher specificity than element.
Red (because .highlight has specificity 10, p has specificity 1).
Question 14
Hard
The page has this code. The paragraph is still black. Why?
<style>
p { color red; }
</style>
<p>Hello</p>There's a missing character.
Missing colon between
color and red. Should be color: red;Question 15
Hard
Build a page with three paragraphs. Use external CSS concept (shown in internal) to style the first paragraph red using inline style, second blue using internal CSS with a class, and third green by default element selector.
Use all 3 methods in one page.
<!DOCTYPE html>
<html>
<head>
<style>
p { color: green; }
.blue { color: blue; }
</style>
</head>
<body>
<p style="color: red;">First (red inline)</p>
<p class="blue">Second (blue class)</p>
<p>Third (green default)</p>
</body>
</html>Multiple Choice Questions
MCQ 1
What does CSS stand for?
Answer: B
B is correct. CSS stands for Cascading Style Sheets. The 'cascading' refers to how styles flow and combine.
B is correct. CSS stands for Cascading Style Sheets. The 'cascading' refers to how styles flow and combine.
MCQ 2
Which symbol separates a CSS property from its value?
Answer: B
B is correct. CSS uses a colon
B is correct. CSS uses a colon
:. Example: color: red;MCQ 3
Which is the BEST practice for adding CSS?
Answer: C
C is correct. External CSS is the best practice. One file styles many pages, keeping code clean and reusable.
C is correct. External CSS is the best practice. One file styles many pages, keeping code clean and reusable.
MCQ 4
Which tag links an external CSS file to HTML?
Answer: C
C is correct.
C is correct.
<link rel="stylesheet" href="style.css"> links an external CSS file. <style> is for internal CSS.MCQ 5
Where should internal CSS be placed?
Answer: B
B is correct. Internal CSS goes in a
B is correct. Internal CSS goes in a
<style> tag within the <head>.MCQ 6
Which attribute is used for inline CSS?
Answer: B
B is correct. The
B is correct. The
style attribute on HTML elements holds inline CSS: <p style="color: red;">MCQ 7
How do you write a comment in CSS?
Answer: C
C is correct. CSS comments use
C is correct. CSS comments use
/* */. HTML uses <!-- -->. They are different languages with different comment styles.MCQ 8
Which CSS rule makes paragraph text red?
Answer: A
A is correct. The CSS syntax is
A is correct. The CSS syntax is
selector { property: value; }. p is the element selector, color is the property, red is the value.MCQ 9
What wraps CSS declarations in a rule?
Answer: C
C is correct. Curly braces
C is correct. Curly braces
{ } wrap the property declarations inside a CSS rule.MCQ 10
Which property changes the text color?
Answer: B
B is correct. The
B is correct. The
color property sets the text color. There is no property called text-color or font-color.MCQ 11
Which character ends a CSS declaration?
Answer: C
C is correct. Every CSS declaration ends with a semicolon
C is correct. Every CSS declaration ends with a semicolon
;. Forgetting it can break the next rule.MCQ 12
Which CSS property sets the background color?
Answer: B
B is correct.
B is correct.
background-color is the standard CSS property for background color.MCQ 13
When multiple CSS sources have the same specificity, which wins?
Answer: C
C is correct. Inline CSS has the highest specificity (1000) and always wins over internal and external CSS when the specificity is otherwise the same.
C is correct. Inline CSS has the highest specificity (1000) and always wins over internal and external CSS when the specificity is otherwise the same.
MCQ 14
Which selector has the highest specificity (among these)?
Answer: C
C is correct. ID selectors (#main) have specificity 100, classes (.note) have 10, and element selectors (p, div) have 1.
C is correct. ID selectors (#main) have specificity 100, classes (.note) have 10, and element selectors (p, div) have 1.
MCQ 15
How do you apply the same rule to multiple selectors?
Answer: B
B is correct. Separate multiple selectors with commas to apply the same rules to all of them:
B is correct. Separate multiple selectors with commas to apply the same rules to all of them:
h1, h2, h3 { color: red; }MCQ 16
What will happen to this code?
<p style='color: red;' class='blue'>Answer: B
B is correct. The inline style (specificity 1000) beats the class selector (specificity 10). The paragraph will be red.
B is correct. The inline style (specificity 1000) beats the class selector (specificity 10). The paragraph will be red.
MCQ 17
Which rel value is used when linking a CSS file?
Answer: B
B is correct.
B is correct.
<link rel="stylesheet" href="style.css">. Without rel="stylesheet", the browser does not treat the file as CSS.MCQ 18
Why is external CSS better than inline CSS?
Answer: B
B is correct. External CSS lets one file style multiple HTML pages. Change one rule, every page updates. Inline CSS has to be repeated everywhere.
B is correct. External CSS lets one file style multiple HTML pages. Change one rule, every page updates. Inline CSS has to be repeated everywhere.
MCQ 19
Which of these is valid CSS syntax?
Answer: C
C is correct. CSS uses curly braces, colons, and semicolons:
C is correct. CSS uses curly braces, colons, and semicolons:
selector { property: value; }MCQ 20
What does this selector target?
h1, h2Answer: B
B is correct. A comma groups selectors. The rule applies to ALL h1 and h2 elements on the page.
B is correct. A comma groups selectors. The rule applies to ALL h1 and h2 elements on the page.
MCQ 21
In the cascade, if two rules have the same specificity, which one wins?
Answer: B
B is correct. When specificity is the same, the later rule wins. This is why order matters in CSS.
B is correct. When specificity is the same, the later rule wins. This is why order matters in CSS.
MCQ 22
Why does the CSS not work when the link tag is missing 'rel="stylesheet"'?
Answer: A
A is correct. Without
A is correct. Without
rel="stylesheet", the browser does not know the linked file is a stylesheet, so it does not apply it (even if it downloads it).MCQ 23
Which of these has specificity of 100?
Answer: C
C is correct. An ID selector (#header) has specificity 100. Element selectors are 1, classes are 10, IDs are 100, inline is 1000.
C is correct. An ID selector (#header) has specificity 100. Element selectors are 1, classes are 10, IDs are 100, inline is 1000.
MCQ 24
What is the correct file structure for external CSS?
Answer: B
B is correct. External CSS requires at least two files: the HTML and the CSS. The HTML links to the CSS using
B is correct. External CSS requires at least two files: the HTML and the CSS. The HTML links to the CSS using
<link rel="stylesheet">.MCQ 25
Which of these CSS rules is INVALID?
Answer: C
C is correct. Missing semicolon after
C is correct. Missing semicolon after
100px. The next property height will not be applied because the parser gets confused.Coding Challenges
Challenge 1: Your First Styled Page
EasyCreate a complete HTML page with internal CSS that has a pastel pink background, Arial font, and a centered blue heading 'Hello, Priya!'.
Sample Input
(No input required)
Sample Output
A pink page with a centered blue heading.
Use internal CSS in a <style> tag in the head. Use body and h1 selectors.
<!DOCTYPE html>
<html>
<head>
<title>My First Styled Page</title>
<style>
body {
background-color: #ffe4e1;
font-family: Arial, sans-serif;
}
h1 {
color: blue;
text-align: center;
}
</style>
</head>
<body>
<h1>Hello, Priya!</h1>
</body>
</html>Challenge 2: Inline CSS Practice
EasyCreate an HTML page with 3 paragraphs styled inline: the first red, the second green, the third blue. All should have a font size of 18px.
Sample Input
(No input required)
Sample Output
Three paragraphs in red, green, and blue.
Use only inline CSS (style attribute).
<!DOCTYPE html>
<html>
<body>
<p style="color: red; font-size: 18px;">This is red.</p>
<p style="color: green; font-size: 18px;">This is green.</p>
<p style="color: blue; font-size: 18px;">This is blue.</p>
</body>
</html>Challenge 3: Dark Theme Page
MediumBuild a page with internal CSS that has a dark grey background (#1a1a2e), white text, and a bright pink heading (#ff4081). Include at least 2 paragraphs and an h1.
Sample Input
(No input required)
Sample Output
A dark page with white text and a pink heading.
Use internal CSS. Hex colors. Must style body, h1, and p.
<!DOCTYPE html>
<html>
<head>
<title>Dark Theme</title>
<style>
body {
background-color: #1a1a2e;
color: white;
font-family: Arial;
padding: 30px;
}
h1 {
color: #ff4081;
text-align: center;
font-size: 40px;
}
p {
font-size: 18px;
line-height: 1.6;
}
</style>
</head>
<body>
<h1>Welcome to the Dark Side</h1>
<p>This is my first dark-themed page. It looks cool and is easy on the eyes.</p>
<p>CSS makes styling fun and powerful.</p>
</body>
</html>Challenge 4: External CSS Setup
MediumCreate two files: an HTML file and a style.css file. The HTML has a heading and a paragraph. The CSS styles the body with a light green background and Arial font, the heading in dark green, and the paragraph in black.
Sample Input
(No input required)
Sample Output
A green-themed page loaded from an external CSS file.
Two separate files. HTML must link style.css with rel="stylesheet".
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>External CSS Demo</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Rohan's Green Page</h1>
<p>This page is styled using an external CSS file.</p>
</body>
</html>
/* style.css */
body {
background-color: #e8f5e9;
font-family: Arial, sans-serif;
padding: 20px;
}
h1 {
color: #1b5e20;
text-align: center;
}
p {
color: black;
font-size: 18px;
}Challenge 5: Grouped Selectors
MediumBuild an HTML page with h1, h2, and h3 headings. Use a single CSS rule (grouped selector) to make all three headings purple and centered. Also style body to have a light grey background.
Sample Input
(No input required)
Sample Output
A page with three purple, centered headings on a grey background.
Use <code>h1, h2, h3</code> as a grouped selector. One rule for all three.
<!DOCTYPE html>
<html>
<head>
<title>Grouped Selectors</title>
<style>
body {
background-color: #f0f0f0;
font-family: Arial;
padding: 20px;
}
h1, h2, h3 {
color: purple;
text-align: center;
}
</style>
</head>
<body>
<h1>Big Heading</h1>
<h2>Medium Heading</h2>
<h3>Small Heading</h3>
</body>
</html>Challenge 6: Profile Card Page
HardBuild a simple profile card: a centered div with a colored background, a heading with the name 'Ananya Kumar', a paragraph with the title 'Web Developer', and another paragraph with an email. Use internal CSS.
Sample Input
(No input required)
Sample Output
A centered card with profile info.
Use padding, max-width, margin auto for centering. Colorful but simple.
<!DOCTYPE html>
<html>
<head>
<title>Profile Card</title>
<style>
body {
background-color: #e3f2fd;
font-family: Arial, sans-serif;
padding: 40px;
}
.card {
background-color: white;
max-width: 300px;
margin: 0 auto;
padding: 25px;
border-radius: 10px;
text-align: center;
}
h1 {
color: #1976d2;
margin-bottom: 5px;
}
p {
color: #555;
margin: 5px 0;
}
</style>
</head>
<body>
<div class="card">
<h1>Ananya Kumar</h1>
<p>Web Developer</p>
<p>ananya@example.com</p>
</div>
</body>
</html>Challenge 7: 3 Methods in One Page
HardCreate an HTML page that uses ALL three CSS methods: external CSS setting body background, internal CSS setting h1 color to red, and inline CSS setting one paragraph to green. Show the order of wins.
Sample Input
(No input required)
Sample Output
A page using all three CSS methods at once.
Demonstrate all three methods. Include comments explaining what each does.
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Three CSS Methods</title>
<!-- External CSS -->
<link rel="stylesheet" href="style.css">
<!-- Internal CSS -->
<style>
h1 { color: red; }
</style>
</head>
<body>
<h1>Three CSS Methods</h1>
<p>Normal paragraph (external styles).</p>
<p style="color: green; font-weight: bold;">Inline green paragraph wins over external.</p>
</body>
</html>
/* style.css */
body {
background-color: #fff9c4;
font-family: Arial;
}
p {
color: blue;
}Challenge 8: Complete Styled Home Page
HardBuild a complete HTML page for 'Vikram's Blog' using external CSS concept (show both files). It should have: a header area with a centered title, 3 paragraphs of introduction text, and styled with a warm color palette (cream background, brown text, dark red headings).
Sample Input
(No input required)
Sample Output
A warm-toned blog home page styled externally.
Two files: index.html and style.css. Use at least 4 CSS rules.
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Vikram's Blog</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Vikram's Blog</h1>
<p>Thoughts on code, life, and learning.</p>
</header>
<main>
<p>Welcome to my blog! I write about web development, programming tips, and my learning journey.</p>
<p>I am a 16-year-old student from Chennai who loves building websites.</p>
<p>Check back often for new posts about HTML, CSS, and JavaScript.</p>
</main>
</body>
</html>
/* style.css */
body {
background-color: #fff8e7;
color: #5d4037;
font-family: Georgia, serif;
padding: 30px;
max-width: 700px;
margin: 0 auto;
}
header {
text-align: center;
border-bottom: 2px solid #5d4037;
padding-bottom: 15px;
margin-bottom: 20px;
}
h1 {
color: #8b0000;
font-size: 42px;
margin-bottom: 5px;
}
p {
font-size: 18px;
line-height: 1.7;
}Need to Review the Concepts?
Go back to the detailed notes for this chapter.
Read Chapter Notes
Learn it live
Want a teacher to take you further than Introduction to CSS - Styling the Web?
Notes explain the idea. A live teacher checks how you think, spots the exact step that slips, and moves at your pace, in a small group or 1-on-1, at a time that suits your time zone.