02. Introduction to CSS & The Rendering Pipeline
🟢 Beginner
1. Definition
CSS (Cascading Style Sheets) is the standard stylesheet language used to specify the visual presentation, typography, colors, layout positioning, and responsive design of documents written in HTML.
2. Why It Is Used
CSS separates web content structure (HTML) from visual appearance. This separation allows developers to update a site's global theme by modifying a single CSS file without altering thousands of HTML pages.
3. How It Works (DOM + CSSOM = Render Tree)
The browser parses HTML into a DOM Tree and CSS into a CSSOM Tree. It combines them into a Render Tree, calculates box geometry in the Layout Phase, and paints pixels on screen during the Paint Phase.
4. Syntax
selector {
property: value;
}
5. Property Value Format Variants
| Format Type | Syntax Example | Description |
|---|---|---|
| Named Keywords | color: red; | Predefined CSS color names |
| Hexadecimal | color: #2563eb; | 6-digit RGB hex code |
| Functional Notation | color: rgb(37 99 235); | Functional RGB / HSL / OKLCH notation |
6. Beginner Example
body {
background-color: #f8fafc;
color: #0f172a;
}
7. Intermediate Example
.card {
background-color: #ffffff;
border-radius: 8px;
padding: 24px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}
8. Advanced Example
.hero-container {
display: flex;
justify-content: space-between;
align-items: center;
background: linear-gradient(135deg, #0f172a, #1e293b);
color: #f8fafc;
}
9. Line-by-Line Code Explanation
.card: Class selector targeting elements withclass="card".border-radius: 8px;: Rounds container corners by 8 pixels.padding: 24px;: Creates internal space between content and box border.
10. Expected Terminal / Browser Output
A clean, elevated card container featuring rounded corners and subtle shadow elevation over a dark/light themed background.
11. Common Mistakes & Pitfalls
- Confusing HTML tags with CSS properties: Writing
<color>in HTML instead of settingcolor: red;in CSS.
12. Important Rules & Limitations
- CSS declarations must end with a semicolon
;or property parsing fails.
13. Multilingual Explanation: English
CSS dictates how HTML elements look on screen. The browser engine parses CSS into a CSSOM tree and merges it with the DOM tree to construct the rendered layout.
14. Multilingual Explanation: Hindi (Roman Script)
CSS HTML content ko style karta hai. Browser DOM aur CSSOM ko mila kar Render Tree banata hai aur screen par final design dikhata hai.
15. Multilingual Explanation: Marathi (Roman Script)
CSS mule HTML elements la colors, fonts, ani spacing dili jaate. Browser DOM ani CSSOM combine karun final layout render karto.
16. Practice Questions
- What is the role of the Render Tree in web browsers?
- What happens during the Layout Phase of browser rendering?
17. Practical Coding Challenge
Write CSS rules for a .profile-box class with background `#ffffff`, border-radius `12px`, padding `30px`, and dark blue heading text `#1e3a8a`.