MODULE 3 β CSS Fundamentals
π¨ Lesson 3.1 β Introduction to CSS
π Making Websites Beautiful with Cascading Style Sheets
π― Learning Objectives
After completing this lesson, students will be able to:
β Understand what CSS is
β Understand why CSS is important
β Understand how CSS works
β Differentiate HTML and CSS
β Apply basic CSS styles
β Add colors to webpages
β Change text appearance
β Create attractive webpages
π Introduction
Imagine building a house.
HTML creates:
π Walls
π Doors
π Windows
π Rooms
But the house still looks plain.
Now imagine adding:
π¨ Paint
ποΈ Furniture
π‘ Lighting
πΌοΈ Decorations
The house becomes beautiful.
Similarly:
HTML creates webpage structure.
CSS makes webpages beautiful.
π€ What is CSS?
CSS stands for:
π¨ Cascading Style Sheets
CSS is used to control:
- Colors
- Fonts
- Layouts
- Backgrounds
- Spacing
- Borders
- Animations
π‘ Simple Definition
CSS is a language used to style and design HTML webpages.
π Why Was CSS Created?
In the early days of web development:
HTML was used for both:
- Structure
- Design
This made webpages difficult to manage.
Example:
<font color="red">
Welcome Students
</font>
This approach became messy.
To solve this problem:
CSS was introduced.
Now:
HTML handles structure.
CSS handles design.
π― HTML vs CSS
| HTML | CSS |
|---|---|
| Structure | Design |
| Creates Content | Beautifies Content |
| Headings | Colors |
| Paragraphs | Fonts |
| Images | Layout |
| Forms | Styling |
π Real Life Example
Think about a human body.
HTML
Skeleton
CSS
Clothes, Hair Style, Appearance
Without CSS:
A webpage works.
But it looks boring.
Example Without CSS
<h1>Welcome Students</h1>
<p>This is Web Designing Course.</p>
Output:
Welcome Students
This is Web Designing Course.
Simple.
Example With CSS
<h1 style="color:blue;">
Welcome Students
</h1>
Output:
Blue heading.
More attractive.
π What Can CSS Control?
CSS controls:
π¨ Colors
Example:
color: red;
Changes text color.
πΌοΈ Background
Example:
background-color: yellow;
Changes background color.
π Fonts
Example:
font-size: 30px;
Changes text size.
π Spacing
Example:
margin: 20px;
Adds spacing.
π§± Borders
Example:
border: 2px solid black;
Creates borders.
π How CSS Works
Process:
HTML Creates Structure
β
CSS Applies Design
β
Browser Displays Styled Page
Example
HTML:
<h1>NextGen Dev Hub</h1>
CSS:
h1{
color:blue;
}
Result:
Blue heading.
π― Ways to Add CSS
There are three ways:
1οΈβ£ Inline CSS
2οΈβ£ Internal CSS
3οΈβ£ External CSS
1οΈβ£ Inline CSS
CSS written directly inside HTML tags.
Example
<h1 style="color:red;">
Welcome Students
</h1>
Output
Red heading.
Understanding
style=
allows CSS inside HTML.
Advantages
β Easy
β Quick
Disadvantages
β Not suitable for large websites.
2οΈβ£ Internal CSS
CSS written inside:
<style>
tag.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1{
color:blue;
}
</style>
</head>
<body>
<h1>Welcome Students</h1>
</body>
</html>
Output
Blue heading.
Advantages
β Better organization
β Suitable for small projects
3οΈβ£ External CSS
Professional method.
CSS stored in a separate file.
Example
File:
style.css
Inside:
h1{
color:green;
}
Connect with HTML:
<link rel="stylesheet"
href="style.css">
Benefits
β Professional
β Reusable
β Easy maintenance
β Used in real websites
π First CSS Property β Color
The most basic CSS property.
Example
color: red;
Complete Example
<h1 style="color:red;">
Welcome Students
</h1>
Output
Red Heading
More Colors
color: blue;
Blue
color: green;
Green
color: purple;
Purple
color: orange;
Orange
π Background Color
Changes background color.
Example
background-color: yellow;
HTML Example
<body style="background-color:yellow;">
Output
Yellow page background.
π Font Size
Controls text size.
Example
font-size: 40px;
HTML Example
<h1 style="font-size:40px;">
Welcome
</h1>
Output
Large heading.
π§± Text Alignment
Controls text position.
Example
text-align:center;
HTML Example
<h1 style="text-align:center;">
Welcome Students
</h1>
Output
Heading appears in center.
π» Complete Example
<!DOCTYPE html>
<html>
<head>
<title>My First CSS Page</title>
</head>
<body
style="background-color:lightblue;">
<h1
style="color:red;
text-align:center;">
Welcome Students
</h1>
<p
style="font-size:20px;">
This is my first CSS webpage.
</p>
</body>
</html>
π― Expected Output
β Light Blue Background
β Red Heading
β Center Aligned Heading
β Large Paragraph Text
π Real World Example
College Website:
<h1
style="color:blue;">
ABC Polytechnic College
</h1>
Blue heading looks more professional than plain black text.
β οΈ Common Beginner Mistakes
Mistake 1
Missing Semicolon
Wrong:
color:red
font-size:20px
Correct:
color:red;
font-size:20px;
Mistake 2
Incorrect Property Name
Wrong:
textcolor:red;
Correct:
color:red;
Mistake 3
Misspelling Style Attribute
Wrong:
<h1 stlye="color:red;">
Correct:
<h1 style="color:red;">
π Best Practices
β Use CSS for design.
β Keep HTML for structure.
β Use meaningful colors.
β Avoid too many colors.
β Use External CSS for large projects.
π Mini Project β Colorful Student Profile
<!DOCTYPE html>
<html>
<head>
<title>Student Profile</title>
</head>
<body
style="background-color:lightyellow;">
<h1
style="color:blue;
text-align:center;">
Rahul Kumar
</h1>
<p
style="font-size:20px;">
Polytechnic Student
</p>
<p
style="color:green;">
Learning Web Designing
</p>
</body>
</html>
π Practical Activity
Create a webpage containing:
Your Name
Blue Color
Your College Name
Green Color
Background Color
Light Yellow
Career Goal
Font Size 20px
Run in Chrome.
π Assignment
Assignment 2.1
Answer the following:
- What does CSS stand for?
- Why is CSS used?
- What is the difference between HTML and CSS?
- Name three ways to add CSS.
- Which CSS property changes text color?
- Which property changes background color?
- Create a webpage using CSS colors.
π§ Quiz
Q1. What does CSS stand for?
A. Computer Style Sheets
B. Cascading Style Sheets
C. Creative Style System
D. Cascading System Style
β Answer: B
Q2. Which technology is used for webpage design?
A. HTML
B. CSS
C. SQL
D. Python
β Answer: B
Q3. Which property changes text color?
A. font
B. text
C. color
D. background
β Answer: C
Q4. Which property changes background color?
A. bg
B. background
C. background-color
D. color
β Answer: C
Q5. Which is the professional way to add CSS?
A. Inline CSS
B. Internal CSS
C. External CSS
D. None
β Answer: C
π Lesson Summary
β CSS stands for Cascading Style Sheets.
β CSS is used to style and beautify webpages.
β HTML creates structure, CSS creates design.
β CSS can change colors, fonts, backgrounds, spacing, and layouts.
β CSS can be added using Inline, Internal, and External methods.
β External CSS is the professional approach.
β CSS transforms plain webpages into attractive websites.