CSS Introduction

Introduction

CSS stands for Cascading Style Sheets. It is used to style and design web pages created with HTML.

While HTML is used to structure content, CSS is used to control how that content looks on the screen. With CSS, you can change colors, fonts, layouts, spacing, and overall appearance of a website.

In this lesson, you will learn the basics of CSS and how it works with HTML.

What You’ll Learn

  • What is CSS
  • Why CSS is important
  • How CSS works with HTML
  • Basic CSS syntax
  • Types of CSS

What is CSS?

CSS (Cascading Style Sheets) is a language used to describe the presentation of a webpage.

πŸ‘‰ It controls:

  • Text color & size
  • Background colors & images
  • Margins & padding
  • Borders
  • Page layout
  • Mobile responsiveness
  • Animations

What Happens Without CSS?

Without CSS, web pages appear plain and unstyled. HTML only provides structure, not design.

Example Without CSS:

<h1>Welcome</h1>
<p>This is a simple webpage.</p>

πŸ‘‰ Output:

  • Default font
  • No colors
  • No spacing control
  • Basic layout

Example With CSS:

<style>
  h1 {
    color: blue;
  }  p {
    font-size: 18px;
    color: gray;
  }
</style>
<h1>Welcome</h1>
<p>This is a styled webpage.</p>

πŸ‘‰ Output:

  • Colored heading
  • Styled text
  • Better readability

CSS transforms a simple HTML page into a visually attractive and user-friendly website.

Why do we need CSS?

Without CSS, web pages look plain and unstyled.

πŸ‘‰ CSS helps you:

  • Make websites visually attractive
  • Improve user experience
  • Create responsive designs
  • Maintain consistency across pages

πŸ”Ή HTML vs CSS

HTMLCSS
StructureStyling
ContentDesign
SkeletonAppearance

πŸ‘‰ Example:

  • HTML β†’ Creates heading
  • CSS β†’ Changes its color and size

How CSS works with HTML

CSS works by selecting HTML elements and applying styles to them.

πŸ‘‰ Example:

<p>This is a paragraph.</p>
p {
  color: blue;
}

πŸ‘‰ The paragraph text will appear in blue.

Basic CSS Syntax

CSS consists of selectors and declarations.

selector {
  property: value;
}

Example:

h1 {
  color: red;
  font-size: 24px;
}

Explanation:

  • h1 β†’ Selector
  • color β†’ Property
  • red β†’ Value

Complete Example

<!DOCTYPE html>
<html>
<head>
    <title>CSS Example</title>
    <style>
        body {
            background-color: lightgray;
        }        h1 {
            color: blue;
        }        p {
            font-size: 18px;
            color: black;
        }
    </style>
</head>
<body><h1>Welcome to CSS</h1>
<p>This is a styled paragraph.</p></body>
</html>

πŸ‘‰ This shows how CSS works in a real webpage.

Types of CSS

There are three ways to apply CSS:

1️⃣ Inline CSS – inside HTML tag
2️⃣ Internal CSS – inside <style> tag
3️⃣ External CSS – separate .css file (BEST way)

1️⃣ Inline CSS

Applied directly inside HTML elements.

<p style="color: blue;">Hello</p>

πŸ‘‰ Not recommended for large projects.

2️⃣ Internal CSS

Written inside <style> tag in <head> section.

<style>
  p {
    color: green;
  }
</style>

3️⃣ External CSS (Recommended)

Written in a separate .css file.

<link rel="stylesheet" href="style.css">

πŸ‘‰ Best for large websites.

CSS Comments

Comments are used to explain code.

/* This is a comment */

πŸ‘‰ They are ignored by the browser.

How CSS Cascading Works

CSS follows a priority system:

  • Inline CSS β†’ Highest priority
  • Internal CSS β†’ Medium
  • External CSS β†’ Lowest

πŸ‘‰ This is called the cascade.

Advantages of CSS

  • Saves time (reuse styles)
  • Easy to maintain
  • Improves page design
  • Supports responsive layouts

Real-Life Uses of CSS

  • Designing websites
  • Creating layouts
  • Styling buttons and forms
  • Making responsive designs

Important Notes

  • Always use external CSS for large projects
  • Keep CSS clean and organized
  • Avoid too much inline CSS
  • Use meaningful selectors

Common Mistakes

  • Missing semicolons
  • Wrong property names
  • Using inline CSS excessively
  • Not linking CSS file properly

Best Practices

  • Use external CSS
  • Write clean and readable code
  • Group related styles
  • Use comments when needed

Practice Tasks

  • Task 1: Change the color of a paragraph using CSS.
  • Task 2: Apply font size to a heading.
  • Task 3: Create an internal CSS example.
  • Task 4: Link an external CSS file.
  • Task 5: Write a simple CSS rule for <h1>.

FAQs

What is CSS?

CSS is used to style and design web pages.

Why is CSS important?

It improves the appearance and user experience of websites.

What are the types of CSS?

Inline, Internal, and External CSS.

Conclusion

CSS is an essential part of web development that helps transform simple HTML pages into visually appealing websites. By understanding CSS basics, syntax, and types, you can start designing your own web pages.

πŸ‘‰ In the next tutorial, you will learn about CSS Syntax & Selectors in detail.

Related Tutorials

  • jQuery AJAX Tutorial for Beginners (Step-by-Step Introduction)

    Introduction Ever noticed how some websites update content instantly without refreshing the page? That’s powered by AJAX. AJAX (Asynchronous JavaScript and XML) allows websites to communicate with the server in the background and update content dynamically β€” without reloading the entire page. With jQuery, using AJAX becomes much easier because it provides simple methods like…

  • CSS Syntax & Selectors

    Introduction CSS syntax defines how styles are written and applied to HTML elements. Selectors are used to target specific elements on a webpage and apply styles to them. Understanding CSS syntax and selectors is essential for writing effective and clean CSS code. In this lesson, you will learn the basic structure of CSS and different…

  • Colors, Units & Backgrounds

    Introduction CSS allows you to control the appearance of web pages using colors, units, and background properties. These are essential for designing visually appealing and responsive websites. In this lesson, you will learn how to apply colors, use different units, and style backgrounds in CSS. What You’ll Learn These are core CSS skills used on…

  • CSS Borders & Box Model

    Introduction CSS borders and the box model are essential concepts for designing layouts and controlling spacing in web development. Every HTML element is treated as a rectangular box, and understanding how this box works helps you create clean and structured designs. In this lesson, you will learn how to style borders and understand the CSS…

  • CSS Display & Position

    Introduction CSS display and position properties control how elements are shown and placed on a web page. These properties are essential for creating layouts, aligning elements, and building modern web designs. In this lesson, you will learn how different display types work and how positioning helps control element placement. What You’ll Learn πŸ”Ή CSS Display…

  • CSS Flexbox

    Introduction CSS Flexbox is a powerful layout system used to design flexible and responsive layouts. It makes it easy to align items, distribute space, and create modern UI designs without using complex positioning or floats. Flexbox works on a one-dimensional layout (row or column) and is widely used in real-world web development. What You’ll Learn…

Leave a Reply

Your email address will not be published. Required fields are marked *