Practice and reinforce the concepts from Lesson 3
In this activity, you will:
Estimated time: 30-40 minutes
Time needed: 2-3 minutes
index.html
, style.css
, and package.json
:warning: Important: Before You Start DO NOT DELETE the existing files in the template:
- Package files
- Any other files you didn't create
ONLY EDIT the necessary files (index.html and style.css).
What you'll do: Understand the project structure and connect your CSS
Time needed: 3-5 minutes
index.html
, style.css
, and package.json
style.css
file is already created for you<head>
section:
<link rel="stylesheet" href="style.css">
tip
Place the <link>
tag after the <title>
tag in your HTML head section for better organization.
What you should achieve: Your goal is to recreate this styled webpage
Time needed: 2 minutes
Style requirements:
What you'll do: Build the content structure
Time needed: 5-7 minutes
Add the following content to your HTML body:
First Section - Favorite Food:
<h1>
heading: "My Favourite Food"<p>
paragraph: "The list below is showing my favourite food"<ol>
with three items:
Second Section - Hobbies:
<h1>
heading: "My Hobby"<p>
paragraph: "The list below is showing my hobby when I am free"<ul>
with three items:
tip Remember to use proper HTML structure with opening and closing tags for all elements!
What you'll learn: CSS directly in HTML elements
Time needed: 3 minutes
<body>
tag in the HTML file<body style="background-color: darkcyan;">
Key concept: Inline CSS uses the style
attribute directly on HTML elements. It has the highest priority among all CSS methods.
tip Inline CSS is best for quick, one-off styles but not recommended for larger projects as it mixes presentation with content.
What you'll learn: CSS within the HTML document
Time needed: 5 minutes
<head>
section<style>
tag inside the <head>
section<style>
h1 {
color: gold;
}
li {
font-weight: bold;
}
</style>
Key concept: Internal CSS goes inside <style>
tags and affects all matching elements in the current document.
What you'll learn: CSS in a separate file
Time needed: 5 minutes
style.css
file in your projectp {
color: white;
background-color: purple;
}
<head>
(you should have done this in Step 1):
<link rel="stylesheet" href="style.css">
Key concept: External CSS is stored in separate .css
files and can be reused across multiple HTML pages.
tip If your external styles aren't working, double-check that:
<link>
tag matches exactly (case-sensitive)<link>
tag is in the <head>
sectionTime needed: 3 minutes to review
CSS Method Comparison:
Method | Where It's Written | Priority | Best Use Case |
---|---|---|---|
Inline CSS | Directly in HTML elements using style attribute |
Highest | Quick fixes, email templates |
Internal CSS | In <style> tags within <head> |
Medium | Single-page styles |
External CSS | In separate .css files |
Lowest | Multi-page websites |
Priority Rule: When multiple methods style the same element, inline CSS wins!
tip CSS Priority If you have conflicting styles, remember: Inline > Internal > External. This is why your body background (inline) will always show, even if you add different background colors in internal or external CSS.
Time needed: 3 minutes
Checklist - Make sure you have:
tip Final Check Compare your output with the expected result image. If something doesn't match:
Styles not appearing?
<link>
tag has the correct file nameColors look different?
darkcyan
, gold
, purple
, white
background-color
not bgcolor
)Lists not formatting correctly?
<ol>
for ordered lists and <ul>
for unordered lists<li>
tags:information_source: Info Submit Your Work When you have completed your "Introduction to CSS" project and verified all styling requirements:
Make sure to test all your styles and verify they match the expected output before submitting!
Great job! You've now learned how to use all three CSS methods to style a webpage! :tada: