Learning›CSS Tutorial›Introduction
CHAPTER 01 · BEGINNER

Introduction to CSS

HTML page ka structure banata hai, aur CSS us structure ko visually attractive banata hai. CSS se colors, spacing, fonts, layouts aur responsive design control kiye jaate hain.

English + Hinglish15 min readPractice included

What is CSS?

CSS stands for Cascading Style Sheets. It is the language used to control how HTML elements look on the screen.

example.cssCSS
h1 {
  color: blue;
}
Hinglish Explanation

HTML me <h1> heading banati hai. CSS me hum h1 select karke uska color, size, spacing aur bahut kuch change kar sakte hain.

HTML and CSS together

Think of HTML as the structure of a house and CSS as its paint, spacing, furniture arrangement and visual design.

index.htmlHTML
<h1>My Learning Website</h1>
<p>I am learning CSS.</p>
style.cssCSS
h1 {
  color: #0b7cff;
}

p {
  font-size: 18px;
}

The HTML content stays the same, while CSS controls its appearance.

Why do we need CSS?

  • Colors aur typography control karne ke liye.
  • Spacing aur alignment improve karne ke liye.
  • Page layouts banane ke liye.
  • Mobile, tablet aur desktop responsive design ke liye.
  • Hover effects aur animations ke liye.
  • Same design multiple pages par reuse karne ke liye.
Important: HTML content aur meaning ke liye hai. CSS presentation aur layout ke liye hai. Dono ko alag responsibility dena clean web development practice hai.

Anatomy of a CSS rule

rule.cssCSS
p {
  color: green;
  font-size: 18px;
}

This CSS rule has three important ideas:

  • p is the selector.
  • color and font-size are properties.
  • green and 18px are values.
Simple Formula

selector { property: value; } — pehle element select karo, phir uski property choose karo, phir value do.

Your first CSS style

Create two files in the same folder: index.html and style.css.

index.htmlHTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>CSS Practice</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Hello CSS</h1>
  <p>I am styling my first page.</p>
</body>
</html>
style.cssCSS
body {
  background-color: #f5f8fc;
}

h1 {
  color: #0b7cff;
}

p {
  color: #334155;
  font-size: 18px;
}
Hinglish Explanation

<link rel="stylesheet" href="style.css"> HTML file ko CSS file se connect karta hai. Ab style.css ke rules HTML elements par apply honge.

Why is it called “Cascading”?

CSS can receive styles from multiple rules. The browser decides which style wins based on factors such as order, specificity and importance. You will learn this properly in the selectors and specificity chapter.

cascade.cssCSS
p {
  color: blue;
}

p {
  color: red;
}

When both rules have equal strength, the later rule usually wins, so the paragraph becomes red.

How the browser applies CSS

When a browser loads a page, it reads the HTML structure and the linked stylesheets, matches selectors against elements, resolves the cascade, and then calculates the final styles used for layout and painting. You do not need to memorize the rendering engine, but this mental model helps with debugging: first confirm the stylesheet loaded, then confirm the selector matches, then inspect which declaration wins.

This separation also makes projects easier to maintain. One stylesheet can style many headings, buttons or cards without changing the HTML content itself. If a design token or shared class changes, every matching element can update together instead of repeating visual attributes throughout the markup.

A first look at inheritance

Some CSS properties, especially text-related properties such as color and font-family, can be inherited by child elements. Other properties such as margins, borders and widths normally are not inherited. Inheritance is different from the cascade: the cascade chooses a winning declaration for an element, while inheritance can pass certain computed values from a parent when the child has no more specific value of its own.

Debugging mindset

Agar style expected result nahi de raha, DevTools me element inspect karo. Dekho rule apply ho raha hai ya crossed-out hai, value parent se inherit hui hai ya kisi stronger selector ne override ki hai. Ye habit CSS ko guesswork se predictable system me convert kar deti hai.

Common beginner mistakes

  • CSS file ka path galat likhna.
  • Property ke baad colon : bhoolna.
  • Declaration ke end me semicolon ; bhoolna.
  • Curly braces { } close na karna.
  • HTML file me CSS ko link na karna.
  • Property ya value ki spelling wrong likhna.
Debugging tip: Agar CSS apply nahi ho raha, sabse pehle stylesheet path, selector spelling aur browser refresh check karo.

Practice Task

Apne HTML Learning Profile project ko CSS se basic style do.

  1. style.css file banao.
  2. HTML me external stylesheet link karo.
  3. Page ka background light color karo.
  4. h1 ka color blue karo.
  5. Paragraph ka text color aur font size change karo.
  6. At least ek aur element ko khud style karo.