- Understand what CSS is and why it matters
- Apply CSS using three methods
- Write CSS selectors and rules
- Use basic CSS properties for styling
- Link external stylesheets
BMC201 - Web Technology
2026-02-05
Lecture 8
Introduction to CSS
Week 2 | Unit I: HTML Forms & CSS Introduction
BMC201 - Web Technology
Mr. Prashant Kumar Nag, Assistant Professor
Learning Objectives
CSS: Cascading Style Sheets
CSS separates content from presentation
HTML = Skeleton (structure)
CSS = Clothes & appearance
JS = Movement & interaction
Three Ways to Apply CSS
CSS Rule Syntax
┌─────────────────────────────────────┐
│ selector { property: value; } │
└─────────────────────────────────────┘
↓ ↓ ↓
What Which To what
to style property value
Example:
Common CSS Selectors
Classes vs IDs
<!-- Classes (reusable) -->
<p class="highlight">Important text</p>
<p class="highlight">More important text</p>
<span class="highlight">Also important</span>
<!-- IDs (unique) -->
<div id="header">Page Header</div>
<h1>Title</h1>
<!-- There should only be ONE element with id="header" -->In CSS:
CSS Color Properties
color: red; /* Text color */
background-color: #f0f0f0; /* Background color */
border: 2px solid blue; /* Border color */
opacity: 0.8; /* Transparency (0-1) */Color formats:
CSS Font Styling
font-family: Arial, sans-serif; /* Font type */
font-size: 16px; /* Size -->
font-weight: bold; /* Bold, 100-900 -->
font-style: italic; /* Italic -->
text-align: center; /* Alignment -->
text-decoration: underline; /* Underline, overline, etc -->Safe fonts:
The CSS Box Model
Every element has padding, border, and margin:
╔════════════════════════════════╗
║ MARGIN (Outside) ║
║ ┌──────────────────────────┐ ║
║ │ BORDER │ ║
║ │ ┌────────────────────┐ │ ║
║ │ │ PADDING (Inside) │ │ ║
║ │ │ ┌──────────────┐ │ │ ║
║ │ │ │ CONTENT │ │ │ ║
║ │ │ └──────────────┘ │ │ ║
║ │ └────────────────────┘ │ ║
║ └──────────────────────────┘ ║
╚════════════════════════════════╝
Margin & Padding
margin: 10px; /* Space outside (all sides) -->
padding: 20px; /* Space inside (all sides) -->
margin: 10px 20px; /* Top/bottom, left/right -->
padding: 10px 20px 30px 40px; /* Top, right, bottom, left -->
border: 2px solid red; /* Width, style, color -->Individual sides:
Dimensions in CSS
width: 300px; /* Fixed width in pixels -->
width: 100%; /* Percentage of parent -->
width: 100vw; /* Percentage of viewport -->
height: auto; /* Automatic height -->
max-width: 500px; <!-- Responsive: max size -->Responsive sizing:
Linking External CSS (Best Practice)
Create a separate style.css file:
/* style.css */
body {
background-color: #f5f5f5;
font-family: Arial, sans-serif;
}
h1 {
color: #333;
text-align: center;
}
p {
line-height: 1.6;
margin-bottom: 15px;
}In your HTML:
One CSS file styles all HTML pages!
CSS Best Practices
.red-button not .x123CSS Custom Properties (Variables)
Define and reuse values:
:root {
--primary-color: #0066cc;
--secondary-color: #ff9900;
--font-size: 16px;
}
h1 { color: var(--primary-color); }
p { color: var(--secondary-color); }
button { font-size: var(--font-size); }Change color in one place, updates everywhere!
Resources & References
Questions?
Next: Week 3 - CSS Styling & JavaScript Introduction