Special Offer Diwali Special Bundle Offer: 3 courses for ₹8,999, save ₹9,001 (50% OFF)! Limited seats available. View Bundles →
0% Completed
Tutorials / CSS Tutorial / Chapter 1: Foundations & Selectors
CSS ⏱ 8 min read

Introduction to CSS & Inclusion Methods

If HTML is the skeleton of a website, CSS is the skin, clothes, personality, and visual presentation.

What is it?

CSS stands for Cascading Style Sheets. It is a stylesheet language used to describe the presentation and layout of a document written in HTML.

Why is it used?

Without CSS, websites look like black-and-white 1990s word processor documents. CSS controls colors, fonts, spacing, responsive multi-column layouts, and fluid animations across screen sizes.

Detailed Explanation

There are three primary ways to include CSS into an HTML document: 1. External Stylesheet (Recommended): Written in a separate `.css` file and linked in the `<head>` using `<link rel="stylesheet" href="style.css">`. Best for maintainability, caching, and clean code separation. 2. Internal Stylesheet: Placed inside `<style>` tags directly in the `<head>` of an HTML file. Great for single-page templates or email newsletters. 3. Inline CSS: Written directly on an element using the `style="..."` attribute. Discouraged for general use because it violates separation of concerns.

Syntax Structure

Syntax Blueprint
/* CSS Rule Syntax */
selector {
  property: value;
}

Code Example

CSS Code
<!-- External linking preferred -->
<link rel="stylesheet" href="/static/css/style.css">

<!-- Internal CSS Example -->
<style>
  body {
    background-color: #f7f4ed;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #1c1c1c;
    margin: 0;
    padding: 24px;
  }

  h1 {
    color: #1c1c1c;
    font-size: 28px;
    letter-spacing: -0.5px;
  }
</style>

Explanation of the Code

• `body` selector applies background color, typography, and default text color to the whole page. • `h1` sets custom font-size and tighter letter spacing for modern aesthetic feel.

Expected Output

The web page receives a warm parchment background (#f7f4ed), crisp dark typography, and custom spacing instead of browser defaults.

Real-World Application

Production web applications use external CSS stylesheets bundled and minified by Vite, Webpack, or Tailwind to load instantly on client devices.

Common Mistakes to Avoid

• Using inline styles (`<h1 style="color: red;">`) everywhere, making global site redesigns almost impossible. • Forgetting the `<link>` tag in the `<head>` of HTML.

Quick Practice Challenge

Create an external file `styles.css`, link it to your HTML document, and give the page body a light background and custom font.

Key Takeaways

• CSS defines the visual presentation and layout of HTML. • Always prefer external stylesheets linked via `<link rel="stylesheet">`. • CSS rules consist of a selector, property, and value.