Tutorials CSS Introduction to CSS
Ch 1 / 60
Chapter 1 Beginner 6 min read CSS

Introduction to CSS & How It Works

CSS (Cascading Style Sheets) is the language that transforms plain HTML into beautiful, responsive and accessible web pages. Every colour, font, layout and animation you see on the web is driven by CSS.

What you'll learn
What CSS is and how it works with HTML
CSS syntax: selectors, properties and values
The three ways to add CSS to a page
The cascade, specificity and inheritance
A brief history from CSS1 to CSS3
Writing and previewing your first styled page

What is CSS?

CSS stands for Cascading Style Sheets. It is the standard language used to describe the visual presentation of web pages written in HTML. While HTML creates the structure and content, CSS controls everything you see — colours, fonts, spacing, layout, animations and responsiveness.

CSS is not a programming language. It is a style sheet language — a set of declarative rules that tell browsers how HTML elements should look. Without CSS, every web page would be plain black text on a white background.

Cascading
When multiple style rules target the same element, CSS uses a defined priority order — the "cascade" — to decide which rule wins.
Style
Rules that control visual appearance: colour, size, font, position, animation — everything the user sees on screen.
Sheets
A .css file — a separate document shared across many HTML pages for a consistent design system.

HTML, CSS & JavaScript — The Web Trio

Every modern web page is built on three technologies that work together. Think of building a house: HTML is the bricks and walls, CSS is the paint and interior design, and JavaScript is the electricity that makes everything interactive.

HTML
Structure — defines content: headings, paragraphs, images, links, forms.
CSS
Presentation — controls colours, fonts, layout, spacing and animations.
JavaScript
Behaviour — adds interactivity: click events, data fetching, dynamic updates.
Beginner Tip
Always learn HTML first — CSS needs HTML to have something to style. Once you understand basic HTML structure, CSS will make a lot more sense from day one.

CSS Syntax — Selectors, Properties & Values

Every CSS rule follows the same simple pattern: a selector targets an HTML element, followed by a declaration block with one or more property: value pairs in curly braces.

/* Anatomy of a CSS rule */
h1 {
  color: #264de4; /* property: value; */
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 16px;
}

p {
  color: #52524a;
  line-height: 1.7;
}
Key Terms
Selector — what to target (h1, .class, #id).  Property — what to change (color, font-size).  Value — the setting to apply (red, 16px).

A Brief History of CSS

CSS was created to solve the problem of mixing presentation with content in HTML. Here are the milestones that shaped the language:

1994
Håkon Wium Lie proposes CSS at CERN. Tim Berners-Lee had kept HTML presentational features minimal, so a separate styling language was needed.
1996
CSS Level 1 published by W3C. Covers fonts, colours, text alignment and the basic box model.
1998
CSS Level 2 standardised. Adds absolute positioning, z-index, media types and pseudo-elements like ::before and ::after.
2005–2011
CSS 2.1 clarifies and fixes CSS2. Browser inconsistencies are gradually resolved.
2011–now
CSS3 released as independent modules — Flexbox, Grid, Animations, Custom Properties, Media Queries and more. CSS is now a modular living standard.

Key Features of CSS

Why is CSS the universal language of web design?

Complete Visual Control
Control every aspect of appearance — colours, typography, spacing, borders, shadows and more from a single stylesheet.
Responsive Design
Media queries let you adapt layouts for every screen — from smartwatches to widescreen monitors — without extra plugins.
Flexbox & Grid
Powerful layout systems built into CSS3 that handle complex, responsive arrangements with minimal, readable code.
Animations & Transitions
Smooth hover effects, keyframe animations and transitions — no JavaScript needed for the majority of visual effects.
Custom Properties (Variables)
--brand: #264de4; — reusable values that cascade through your stylesheet and can be updated by JavaScript.
Separation of Concerns
Keeps style separate from content — one CSS file can style dozens of HTML pages, making maintenance effortless.
Accessibility
CSS supports prefers-reduced-motion, high-contrast modes and visible focus styles for assistive technologies.
Cascade & Inheritance
Child elements inherit styles from parents automatically; cascading rules let you override any style at exactly the right level.
Free Resource
CSS3 Cheat Sheet — All Properties & Selectors
One printable page covering every CSS3 property, selector type, unit, layout system and common patterns. Perfect quick reference for beginners and pros.
Download PDF

The Cascade & Specificity

When multiple CSS rules target the same element, the browser uses specificity and source order to decide which one wins. Understanding this is the key to writing predictable CSS.

Inline styles
1,0,0,0
ID selectors
0,1,0,0
Class / attribute
0,0,1,0
Element selectors
0,0,0,1
Avoid !important
!important overrides the entire cascade and makes debugging very difficult. Use it only as a last resort.

The CSS Box Model

Every HTML element on a page is treated as a rectangular box by the browser. The box model defines four areas stacked around every element — from the innermost content outward:

Margin Border Padding Content
Pro Tip
Always add box-sizing: border-box; to your CSS reset. It makes padding and borders included inside the width — far more predictable.

What Can You Do With CSS?

CSS powers virtually every visual aspect of the web:

Themes & Dark Mode
Responsive Layouts
CSS Animations
Complex Grid Systems
Print Stylesheets
Email Templates
Landing Pages
Portfolios
Dashboards
Data Visualisations

Three Ways to Add CSS to a Page

CSS can be applied to HTML in three different ways, each suited to different situations:

HTML — 1. External Stylesheet (Best Practice)
<!-- In your HTML <head> -->
<link rel="stylesheet" href="style.css">

/* In style.css */
body { font-family: sans-serif; background: #f8f8f8; }
HTML — 2. Internal <style> block (Single page)
<style>
  h1 { color: #264de4; }
  p  { font-size: 16px; }
</style>
HTML — 3. Inline style attribute (Avoid — hard to maintain)
<p style="color: red; font-size: 18px;">This is inline CSS.</p>

Your First Styled Page

Copy this complete example, save as index.html and open it in any browser. No setup required.

HTML + CSS — index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My First Styled Page</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background: #e8f0fe;
      display: flex;
      justify-content: center;
      padding: 40px 20px;
    }
    .card {
      background: #ffffff;
      border-radius: 12px;
      padding: 32px;
      max-width: 500px;
      box-shadow: 0 4px 20px rgba(0,0,0,.10);
    }
    h1 { color: #264de4; margin-bottom: 12px; }
    p  { color: #52524a; line-height: 1.7; }
  </style>
</head>
<body>
  <div class="card">
    <h1>Hello, CSS! 🎨</h1>
    <p>This paragraph is styled with CSS. The card has a shadow, rounded corners and a white background.</p>
  </div>
</body>
</html>
How to run it
Copy the code → paste into any text editor → save as index.html → double-click the file. Your browser opens and you'll see your first styled web page instantly!

Try It Yourself

Edit the CSS below and watch the preview update live as you type. Click Open in Editor for a full-screen editing experience.

Live Editor
✎ Editor
👁 Preview
Featured Course — Enroll Now
Modern Web Development With AI
Master HTML, CSS, JavaScript, React and Node.js — all in one industry-ready curriculum. Build real projects with AI-powered tools and get placement support.
120+
Chapters
40 hrs
Content
10 Real
Projects
4.9 ⭐
Rating
HTML5 CSS3 JavaScript React.js Node.js Tailwind CSS AI Tools

Quick Check — Chapter 1

Questions & Answers
CSS stands for Cascading Style Sheets. Its purpose is to control the visual presentation of HTML documents — defining colours, fonts, spacing, layout, animations and responsiveness. Without CSS, every page would appear as unstyled black text on a white background.
A selector targets the HTML element(s) you want to style (e.g. h1, .card). A property is the aspect you want to change (e.g. color, font-size). A value is the setting you apply to that property (e.g. blue, 16px). Together they form a CSS declaration: selector { property: value; }.
The cascade is the algorithm browsers use to decide which CSS rule applies when multiple rules target the same element. It considers three factors in order: origin (browser defaults, author styles, user overrides), specificity (how targeted the selector is), and source order (later rules win when specificity is equal). Understanding the cascade prevents unexpected style conflicts.
1. External stylesheet — a separate .css file linked via <link rel="stylesheet" href="style.css"> in the <head>. Best practice for all real projects.

2. Internal <style> block — CSS written inside a <style> tag in the <head>. Useful for single-page demos.

3. Inline style attribute — styles written directly on an element via style="". Highest specificity, but hardest to maintain — avoid unless necessary.
The CSS Box Model describes the rectangular space every HTML element occupies on the page. From innermost to outermost, the four layers are:

Content — the actual text, image, or element content.
Padding — transparent space between the content and the border.
Border — a visible line (or invisible zero-width) around the padding.
Margin — transparent space outside the border, separating the element from its neighbours.

Setting box-sizing: border-box makes width calculations include padding and border, which is far easier to work with.
Multiple Choice Questions
Question 1 of 5
What does CSS stand for?
Question 2 of 5
Which CSS property changes the text colour of an element?
Question 3 of 5
Which selector type has the highest specificity score?
Question 4 of 5
Which CSS module is best suited to two-dimensional layouts with rows AND columns?
Question 5 of 5
Which CSS property adds space inside an element's border?
Chapter Summary
  • CSS (Cascading Style Sheets) is the language that controls the visual presentation of HTML pages — colours, fonts, layout, spacing and animations.
  • CSS is a style sheet language, not a programming language. It uses declarative property–value rules: h1 { color: blue; }.
  • CSS can be added as an external file (best practice), an internal <style> block, or an inline style="" attribute.
  • The cascade and specificity rules determine which CSS rule wins when multiple rules target the same element.
  • Every element is a box — the box model (content, padding, border, margin) is fundamental to all CSS layout.
  • CSS3 added Flexbox, Grid, Animations, Custom Properties and Media Queries — the building blocks of modern responsive web design.
  • CSS was proposed by Håkon Wium Lie in 1994 and first standardised by W3C as CSS1 in 1996.
~6 min read
Beginner level
Chapter 1 of 60

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel