Lesson 3.1: Introduction to CSS & Syntax
1. What is CSS?
-
CSS (Cascading Style Sheets) is used to style and format the structure built with HTML.
-
It controls the look and feel of the web page — colors, fonts, layout, spacing, and responsiveness.
-
HTML = structure → CSS = design.
2. Why Use CSS?
-
Separation of concerns → Keep structure (HTML) and design (CSS) separate.
-
Consistency → Same styling across multiple web pages.
-
Reusability → One CSS file can be linked to multiple pages.
-
Flexibility → Easy to update design without touching HTML.
3. CSS Syntax
A CSS rule consists of:
Example:
-
Selector → Targets HTML element (
p= paragraph). -
Property → The styling aspect (e.g.,
color). -
Value → The setting for the property (
blue). -
Declaration block → Everything inside
{ }.
4. Selectors in CSS
-
Type selector:
p { color: red; }(targets all<p>). -
Class selector:
.box { border: 1px solid black; }(use withclass="box"). -
ID selector:
#main { background: yellow; }(use withid="main"). -
Universal selector:
* { margin: 0; padding: 0; }(applies to all elements). -
Group selector:
h1, h2, h3 { font-family: Arial; }.
