🎨 Introduction to CSS β€” Complete Beginner-Friendly Tutorial

🌐 What Is CSS?

CSS (Cascading Style Sheets) is a styling language used to control the appearance of HTML content. While HTML gives you the structure (headings, paragraphs, buttons, images), CSS defines how they should look β€” colors, layout, spacing, animations, responsiveness, and more.

>>β€œHTML builds the structure. CSS adds the beauty.”

Note

βœ” CSS = Styling
βœ” HTML = Structure
βœ” JavaScript = Interactivity

🎯 Why Do We Use CSS?

  • 🎨 To add colors, fonts, spacing, and visual design
  • πŸ“± To make websites responsive on all screen sizes
  • 🧱 To control layout (Grid, Flexbox, Positioning)
  • πŸ”₯ To create animations, transitions, and effects
  • ♻️ To separate structure (HTML) from design (CSS)

πŸ“¦ How CSS Works

CSS uses selectors to target elements and apply rules. A rule is made of a selector + declaration block.

Basic CSS Rule

selector {
  property: value;
}

Example: Make all paragraphs blue:

Example

p {
  color: blue;
}

πŸ“Œ Adding CSS to HTML

1️⃣ Inline CSS

Inline CSS

<p style="color: red;">Hello World</p>

Note

Not recommended for real projects.

2️⃣ Internal CSS

Internal CSS

<style>
  h1 {
    color: purple;
  }
</style>

3️⃣ External CSS (Best Practice)

External CSS

<link rel="stylesheet" href="styles.css" />

🎨 CSS Properties You’ll Use Every Day

  • color β†’ Text color
  • background β†’ Background color or image
  • font-size β†’ Text size
  • margin β†’ Spacing outside elements
  • padding β†’ Spacing inside elements
  • border β†’ Lines around elements
  • width / height β†’ Element dimensions

πŸ“ CSS Selectors Overview

  • Element Selector: p
  • Class Selector: .btn
  • ID Selector: #header
  • Universal Selector: *
  • Attribute Selector: [type="text"]
  • Pseudo-class Selector: :hover
  • Pseudo-element Selector: ::before

πŸ“ The β€œCascading” Part of CSS

The word cascading means styles are applied in order of priority:

PrioritySource
1️⃣ HighestInline styles
2️⃣IDs
3️⃣Classes, pseudo-classes, attribute selectors
4️⃣Elements
5️⃣ LowestUniversal selector *

Note

If two rules conflict, CSS chooses the one with higher specificity.

πŸ“± CSS for Responsive Websites

CSS lets websites adapt to different devices using @media queries.

Media Query Example

@media (max-width: 600px) {
  body {
    background: lightgray;
  }
}

🧱 Modern CSS Tools

  • Flexbox β†’ One-dimensional layout
  • Grid β†’ Two-dimensional layout
  • Variables (custom properties): --brand-color
  • Animations & transitions
  • Container queries
  • Nesting (like SCSS)

✨ Example: Styling a Button

CSS Button

.btn {
  background: royalblue;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
}

.btn:hover {
  background: navy;
}

⚠️ Common Mistakes Beginners Make

  • ❌ Using inline CSS everywhere
  • ❌ Forgetting to link your stylesheet
  • ❌ Not using classes (overusing IDs)
  • ❌ Writing overly specific selectors
  • ❌ Not understanding the cascade & specificity

Note

βœ” Start simple. βœ” Use external CSS. βœ” Reuse classes.

πŸ”₯ Summary

CSS is the language that turns your HTML into a beautiful, responsive, modern webpage. By learning selectors, the box model, colors, layout systems, and responsive techniques, you gain full control over how your UI looks.

>>β€œCSS isn’t just decoration β€” it’s the design language of the web.”

Learn more β†’MDN CSS Docs πŸ“˜