Introduction to CSS - Css Styling | Lecture Notes - YNetStudyHub
Css Styling

Introduction to CSS

2 mins read 312 words Topic 1 of 10
Study with AI Tutor Learn 2× faster Instant Q&A Quiz practice
Launch AI Lesson
Text Size:
PDF Save

Overview of what CSS (Cascading Style Sheets) is, its importance in web development, and how it is used to style HTML elements on a webpage.

Introduction to CSS (Cascading Style Sheets)
Version: CSS 3 – current standard


1. What Is CSS?

Aspect Description
Definition A language that describes how HTML (or XML) elements should be rendered on screen, paper, or other media.
Purpose Separates content (HTML) from presentation (styles), enabling:
• Consistent look across pages
• Faster development & maintenance
• Re‑usable design components
Key Idea Cascading – multiple style rules can apply to the same element; the final appearance is determined by a hierarchy of origins, specificity, and source order.

2. Basic Syntax

selector {
    property: value;      /* declaration */
    property2: value2;    /* another declaration */
}
  • Selector – identifies the HTML element(s) to style.
  • Declaration block – set of property: value pairs, each ending with a semicolon.
  • Comments – /* comment text */

3. Types of Selectors

Category Example What It Targets
Element p {} All <p> tags
Class .menu {} Elements with class="menu"
ID #header {} Element with id="header" (unique)
Attribute input[type="text"] {} <input> elements whose type attribute equals text
Descendant nav ul li {} <li> inside <ul> inside <nav>
Child ul > li {} Direct child <li> of <ul>
Pseudo‑class a:hover {} Links when mouse hovers
Pseudo‑element p::first-line {} First line of every <p>
Group h1, h2, h3 {} All three heading levels
Universal * {} Every element (rarely used)

4. The Cascade & Specificity

  1. Origin (order of importance)

    • User agent (browser defaults)
    • User styles (optional)
    • Author styles (your CSS)
    • Important declarations (!important) override all but later !important rules.
  2. Specificity (weight of a selector)

    • Inline style → a=1, b=0, c=0 (most specific)
    • ID → 0,1,0
    • Class / attribute / pseudo‑class → 0,0,1
    • Element / pseudo‑element → 0,0,0,1

    Higher specificity wins; if equal, later rule in the stylesheet wins.


5. Including CSS in a Document

Method Syntax Typical Use
Inline <p style="color:red;">Text</p> Quick test, rarely for production
Embedded <style> p { color:red; } </style> placed in <head> Small projects, single‑page demos
External <link rel="stylesheet" href="styles.css"> Production‑ready, reusable across many pages
Import @import url("theme.css"); inside a CSS file Modularizing
Topic Concept Map
Ask AI Tutor 24/7 Live

Click any prompt to explore this topic interactively with your AI Tutor:

Explain in simple terms Give me 3 practice exam questions Summarize key principles in 5 points
Unit Syllabus 10 Topics
Introduction to CSS
CSS Syntax and Selectors
Upgrade
CSS Box Model
Upgrade
CSS Typography
Upgrade
CSS Colors and Backgrounds
Upgrade
CSS Layouts
Upgrade
CSS Transitions and Animations
Upgrade
CSS Best Practices
Upgrade
CSS Frameworks
Upgrade
CSS Preprocessors
Upgrade