Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Role of CSS in Web Development
📖 Scenario: You are creating a simple webpage to explain how CSS styles change the look of HTML content. This will help you see how CSS controls colors, fonts, and layout.
🎯 Goal: Build a basic HTML page and add CSS styles step-by-step to change the background color, text color, and font size of a heading.
📋 What You'll Learn
Create an HTML skeleton with a heading
Add a CSS variable for the main color
Use CSS to style the heading with the main color and font size
Add a background color to the page using CSS
💡 Why This Matters
🌍 Real World
CSS is used in every website to control how pages look. Learning to use CSS variables and selectors helps you create consistent and easy-to-change styles.
💼 Career
Web developers use CSS daily to design user-friendly and attractive websites. Understanding CSS basics is essential for frontend development jobs.
Progress0 / 4 steps
1
Create the HTML skeleton with a heading
Write the basic HTML structure with lang="en", charset="UTF-8", and a <h1> heading that says "Welcome to CSS Styling" inside the <body>.
CSS
Hint
Remember to include lang="en" in the <html> tag and add a heading inside the body.
2
Add a CSS variable for the main color
Inside the <head>, add a <style> block. Define a CSS variable called --main-color with the value #2a9d8f inside the :root selector.
CSS
Hint
Use :root to define global CSS variables. Write --main-color: #2a9d8f; inside it.
3
Style the heading with the main color and font size
In the existing <style> block, add a CSS rule for h1 that sets color to var(--main-color) and font-size to 2.5rem.
CSS
Hint
Use color: var(--main-color); and font-size: 2.5rem; inside the h1 selector.
4
Add a background color to the page using CSS
In the same <style> block, add a CSS rule for body that sets background-color to #e9f5f2.
CSS
Hint
Set background-color: #e9f5f2; inside the body selector.
Practice
(1/5)
1. What is the main role of CSS in web development?
easy
A. To style and control the appearance of web pages
B. To add interactivity to web pages
C. To store data on the server
D. To write the content of web pages
Solution
Step 1: Understand CSS purpose
CSS is used to style web pages by changing colors, fonts, and layout.
Step 2: Compare with other web technologies
JavaScript adds interactivity, HTML provides content, and servers store data, so these are not CSS roles.
Final Answer:
To style and control the appearance of web pages -> Option A
Quick Check:
CSS = Styling [OK]
Hint: Remember: CSS = style and layout [OK]
Common Mistakes:
Confusing CSS with JavaScript for interactivity
Thinking CSS handles content or data storage
Mixing CSS with HTML roles
2. Which of the following is the correct way to apply a CSS style to all paragraphs in HTML?
easy
A. p { color: blue; }
B.
C. paragraph { color: blue; }
D. all(p) { color: blue; }
Solution
Step 1: Identify CSS selector syntax
The selector for paragraphs is p, followed by curly braces with styles inside.
Step 2: Check each option
p { color: blue; } uses correct CSS syntax.
is inline HTML, not CSS. paragraph { color: blue; } uses wrong selector name. all(p) { color: blue; } is invalid CSS syntax.
Final Answer:
p { color: blue; } -> Option A
Quick Check:
CSS selector for paragraphs = p [OK]
Hint: CSS selectors match HTML tags directly [OK]
Common Mistakes:
Using HTML inline styles instead of CSS rules
Wrong selector names like 'paragraph'
Invalid CSS syntax with unknown functions
3. Given this CSS and HTML, what color will the text inside the <h1> tag be?
h1 { color: red; } h1.special { color: green; }
<h1 class='special'>Hello</h1>
medium
A. Blue
B. Red
C. Green
D. Black (default)
Solution
Step 1: Understand CSS specificity
The selector h1.special is more specific than just h1, so it overrides the color.
Step 2: Apply styles to the HTML element
The <h1> has class 'special', so the green color applies.
Final Answer:
Green -> Option C
Quick Check:
More specific selector wins = Green [OK]
Hint: More specific CSS selectors override less specific ones [OK]
Common Mistakes:
Ignoring class selectors specificity
Assuming first declared style always applies
Confusing color names
4. What is wrong with this CSS code?
body { font-size 16px; color: black }
medium
A. Color value should be uppercase
B. Missing colon after font-size property
C. font-size should be in quotes
D. No closing brace for body selector
Solution
Step 1: Check CSS property syntax
Each property must have a colon between name and value. Here, font-size 16px; misses the colon.
Step 2: Verify other parts
Color value can be lowercase, quotes are not needed for sizes, and the closing brace is present.
Final Answer:
Missing colon after font-size property -> Option B
Quick Check:
CSS properties need colons [OK]
Hint: CSS properties always need a colon between name and value [OK]
Common Mistakes:
Forgetting colons after property names
Thinking quotes are needed for numeric values
Assuming color names must be uppercase
5. You want a website to look good on phones and computers. Which CSS approach helps achieve this?
hard
A. Avoid CSS and rely on HTML only
B. Write separate CSS files for phones and computers without linking both
C. Use only fixed pixel widths for all elements
D. Use media queries to adjust styles based on screen size
Solution
Step 1: Understand responsive design
Responsive design means the website adapts to different screen sizes like phones and computers.
Step 2: Identify CSS technique for responsiveness
Media queries let CSS apply different styles depending on screen width, making the site look good everywhere.
Final Answer:
Use media queries to adjust styles based on screen size -> Option D
Quick Check:
Responsive design uses media queries [OK]
Hint: Media queries adapt styles to screen sizes [OK]