HTML & CSS - Mastery / CSS Basics

What is CSS

❓What is CSS?

  • CSS stands for Cascading Style Sheets.

  • It’s what makes your plain HTML look beautiful.

  • If HTML is the structure of a house (walls, windows, doors), CSS is the paint, decoration, layout, and styling.


Master Code Block (This will be used for further examples)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>CSS Basics</title>
    <style>
       <!--All CSS content to be added here-->
    </style>
  </head>
  <body>
    <!--All HTML content to be added here-->
  </body>
</html>

✨ Why Do We Need CSS?

HTML is all about the content, but CSS handles the appearance.

📕 Without CSS:

<h1>Hello</h1>
<p>This is a paragraph.</p>

📗 With CSS:

<style>
  h1 {
    color: royalblue;
    font-size: 60px;
    text-align: center;
  }

  p {
    font-family: Arial;
    line-height: 1.6;
    text-align: center; /* Center align the paragraph */
    font-size: 40px; /* Increase font size */
  }
</style>
<h1>Hello</h1>
<p>This is a paragraph.</p>

🧩 CSS Basic Structure

selector {
  property: value;
}
  • Selector → What you're styling (e.g., h1, p, .class, #id)

  • Property → What aspect you want to change (e.g., color, font-size)

  • Value → The new value you want to apply (e.g., blue, 16px)


♦ Quick Chart – CSS Selectors

Selector Type

Example

What It Targets

Element

p

All <p> tags

Class

.btn

All elements with class="btn”

ID

#header

The element with id="header”

Grouping

h1, p

All <h1> and <p> elements

Universal

*

Targets everything


☘ Example: Styling a Button


🌱 How to Add CSS (3 Ways)

Method

Description

Where it goes

Inline CSS

Styles written directly in HTML elements

Not recommended

Internal CSS

CSS inside a <style> tag in the HTML <head>

Good for small sites

External CSS

CSS in a separate .css file

Best practice


✅ CSS in One Line

CSS controls how your webpage looks — colors, fonts, spacing, layout, animations — all the visual stuff!