CSS Basics – Styling the Web

I’m Arjun Saxena, a passionate software developer specializing in web engineering. I believe in writing code that creates real solutions to real problems. I love building efficient, user-friendly applications and constantly push myself to learn new technologies. Beyond coding, I enjoy sharing knowledge and growing together with others in the tech community.
HTML gives structure to a webpage, but CSS makes it beautiful 🎨
Without CSS, every website would look plain and boring.
In this blog, you’ll learn:
What CSS is and why it matters
The CSS Box Model (content, padding, border, margin)
How spacing affects layout
CSS specificity (which style wins and why)
Difference between class and ID
Common beginner mistakes to avoid
No complex design theory — just solid basics.
1️⃣ What is CSS?
Simple Definition:
CSS (Cascading Style Sheets) is used to style and layout web pages.
CSS controls:
Colors 🎨
Spacing 📦
Fonts ✍️
Layout 📐
Example: HTML Without vs With CSS
HTML only
<h1>Hello World</h1>
<p>This is a paragraph</p>
With CSS
h1 {
color: blue;
}
p {
font-size: 18px;
}
👉 Same content, better appearance.
2️⃣ Understanding the CSS Box Model (Very Important)
Every HTML element is treated as a box in CSS.
CSS Box Model = Content + Padding + Border + Margin
📦 CSS Box Model Diagram
ox Model Parts Explained
| Part | Meaning |
| Content | Actual text or image |
| Padding | Space inside the box |
| Border | Wraps padding & content |
| Margin | Space outside the box |
3️⃣ Box Model – Practical Example
<div class="box">Hello CSS</div>
.box {
width: 200px;
padding: 20px;
border: 5px solid black;
margin: 15px;
}
What Happens?
Content width = 200px
Padding adds space inside
Border surrounds content
Margin pushes other elements away
👉 Spacing directly affects layout.
4️⃣ Why Box Model Matters?
If you don’t understand the box model:
Layouts break ❌
Spacing feels confusing ❌
Elements don’t align ❌
✔ Box model = predictable layouts
✔ Essential for responsive design
5️⃣ CSS Selectors: Class vs ID
Class Selector (.)
.card {
background-color: lightgray;
}
<div class="card"></div>
<div class="card"></div>
✔ Reusable
✔ Used multiple times
ID Selector (#)
#header {
background-color: blue;
}
<div id="header"></div>
✔ Unique
❌ Use only once
Simple Rule:
👉 Class for styling
👉 ID for unique elements
6️⃣ CSS Specificity (Who Wins the Style?)
Sometimes multiple CSS rules apply to the same element.
Specificity decides which rule wins
Specificity Order (Low → High)
Element selector (
p)Class selector (
.box)ID selector (
#box)Inline styles (
style="")
Example:
p {
color: blue;
}
.text {
color: green;
}
#para {
color: red;
}
<p id="para" class="text">Hello</p>
👉 Text color = red
Because ID selector wins.
7️⃣ CSS Specificity Algorithm (Simple Table)
| Selector | Specificity Value |
| Element | 0-0-1 |
| Class | 0-1-0 |
| ID | 1-0-0 |
| Inline style | Highest |
✔ Higher value wins
✔ Avoid unnecessary conflicts
8️⃣ Common Beginner Mistakes (Must Avoid)
❌ Overusing inline styles
<p style="color:red">Bad practice</p>
❌ Using IDs everywhere
❌ Not understanding box model
❌ Fighting CSS with !important
Better Practice ✔
.text {
color: red;
}
✔ Clean
✔ Reusable
✔ Maintainable
9️⃣ How CSS Improves a Web Page (Before & After)
Before:
No spacing
No colors
Hard to read
After:
Clear layout
Good spacing
Better user experience




