π MODULE 3 β CSS Fundamentals
ποΈ Lesson 3.2 β Inline CSS
π¨ Applying CSS Directly Inside HTML Elements
π― Learning Objectives
After completing this lesson, students will be able to:
β Understand Inline CSS
β Apply CSS Directly to HTML Elements
β Change Text Colors
β Change Background Colors
β Change Font Size
β Align Text
β Create Beautiful Webpages Using Inline CSS
π Introduction
In the previous lesson, we learned:
HTML creates webpage structure.
CSS makes webpages beautiful.
Now the question is:
Where do we write CSS?
There are three ways:
1οΈβ£ Inline CSS
2οΈβ£ Internal CSS
3οΈβ£ External CSS
In this lesson, we will learn:
ποΈ Inline CSS
π€ What is Inline CSS?
Inline CSS means writing CSS directly inside an HTML tag.
Example:
<h1 style="color:red;">
Welcome Students
</h1>
Here
style=""
contains CSS code.
π Why is it Called Inline CSS?
Because CSS is written inside the same line as the HTML element.
Example:
<p style="color:blue;">
Hello
</p>
HTML and CSS are together.
ποΈ Syntax of Inline CSS
<tag style="property:value;">
Content
</tag>
Example
<h1 style="color:red;">
Welcome Students
</h1>
Understanding the Code
color:red;
Means:
Text Color = Red
Output
Welcome Students
Displayed in Red Color.
π¨ Changing Text Color
Property:
color:
Example
<h1 style="color:blue;">
NextGen Dev Hub
</h1>
Output
Blue Heading
More Examples
<p style="color:green;">
Learning CSS
</p>
<p style="color:orange;">
Web Designing Course
</p>
Common Color Names
red
blue
green
yellow
orange
purple
black
white
π Changing Background Color
Property:
background-color:
Example
<h1 style="background-color:yellow;">
Welcome Students
</h1>
Output
Yellow Background
Example
<p style="background-color:lightblue;">
Learning CSS
</p>
π Changing Font Size
Property:
font-size:
Example
<h1 style="font-size:40px;">
NextGen Dev Hub
</h1>
Meaning
Text Size = 40 Pixels
Example
<p style="font-size:25px;">
Web Designing Course
</p>
π― Text Alignment
Property:
text-align:
Center Alignment
<h1 style="text-align:center;">
Welcome Students
</h1>
Output
Centered Heading
Left Alignment
text-align:left;
Right Alignment
text-align:right;
Example
<p style="text-align:right;">
Right Side Text
</p>
π Multiple CSS Properties
We can use multiple properties together.
Example
<h1
style="
color:white;
background-color:blue;
font-size:40px;
text-align:center;
">
NextGen Dev Hub
</h1>
Output
White Text
Blue Background
Large Font
Centered Text
Understanding Semicolon
Each property ends with:
;
Example:
color:red;
font-size:30px;
text-align:center;
π¨ Styling Paragraphs
Example
<p
style="
color:green;
font-size:20px;
">
Learning CSS Fundamentals
</p>
Output
Green Large Paragraph
π» Complete Example Program
<!DOCTYPE html>
<html>
<head>
<title>Inline CSS Example</title>
</head>
<body>
<h1
style="
color:white;
background-color:blue;
font-size:40px;
text-align:center;
">
NextGen Dev Hub
</h1>
<p
style="
color:green;
font-size:20px;
">
Learning Web Designing
</p>
</body>
</html>
π― Expected Output
Blue Background Heading
White Text
Large Font
Centered Alignment
Green Paragraph
π« Real World Example
Student Profile Page
<h1
style="
color:blue;
">
Rahul Kumar
</h1>
<p
style="
color:green;
">
Polytechnic Student
</p>
π Creating a Colorful Webpage
Example
<h1 style="color:red;">
Welcome
</h1>
<h2 style="color:blue;">
Web Designing
</h2>
<h3 style="color:green;">
Course
</h3>
Output
Three headings with different colors.
β οΈ Common Beginner Mistakes
Mistake 1
Missing Style Attribute
Wrong:
<h1 color="red">
Welcome
</h1>
Correct:
<h1 style="color:red;">
Welcome
</h1>
Mistake 2
Forgetting Semicolon
Wrong:
color:red
Correct:
color:red;
Mistake 3
Incorrect Property Name
Wrong:
text-color:red;
Correct:
color:red;
π Advantages of Inline CSS
β Easy to Learn
β Quick Styling
β Useful for Small Projects
β Beginner Friendly
β Disadvantages of Inline CSS
β Repeated Code
β Difficult to Manage Large Websites
β Not Professional for Big Projects
π Best Practices
β Use Inline CSS for learning.
β Use meaningful colors.
β Keep designs simple.
β Use multiple properties carefully.
π Mini Project β Student Introduction Page
Create:
<h1
style="
color:blue;
text-align:center;
">
Rahul Kumar
</h1>
<p
style="
color:green;
font-size:20px;
">
Polytechnic Student
</p>
π Practical Activity
Create a webpage containing:
Your Name
Blue Color
Centered
College Name
Green Color
Career Goal
Red Color
Large Font
Favorite Subject
Yellow Background
Run it in Chrome Browser.
π Assignment
Assignment 3.2
- What is Inline CSS?
- Which attribute is used for Inline CSS?
- Which property changes text color?
- Which property changes background color?
- Which property changes font size?
- Which property aligns text?
- Create a colorful webpage using Inline CSS.
π§ Quiz
Q1. Which attribute is used for Inline CSS?
A. css
B. design
C. style
D. color
β Answer: C
Q2. Which property changes text color?
A. background
B. color
C. text
D. font
β Answer: B
Q3. Which property changes background color?
A. background-color
B. color
C. bg
D. fill
β Answer: A
Q4. Which property changes font size?
A. size
B. text-size
C. font-size
D. font
β Answer: C
Q5. Which property centers text?
A. align
B. text-align
C. center
D. position
β Answer: B
π Lesson Summary
β Inline CSS is written inside HTML elements.
β
The style attribute is used for Inline CSS.
β
color changes text color.
β
background-color changes background color.
β
font-size changes text size.
β
text-align aligns text.
β Inline CSS is simple and beginner-friendly.