Level 1: CSS FundamentalsEstimated: 12-18 min
Introduction to CSS
CSS (Cascading Style Sheets) is the stylesheet language used to describe the presentation and layout of a document written in HTML. While HTML provides the skeleton and semantic structure, CSS gives websites their visual beauty, responsive layout, colors, typography, and fluid animations.
What You Will Master in This Lesson
- •Understand what CSS is and how it separates content (HTML) from presentation (CSS).
- •Learn the three ways to attach CSS: Inline, Internal `<style>`, and External `.css` stylesheets.
- •Master the CSS rule structure: Selector, Property, and Value.
- •Apply custom typography, background colors, and border radius in the interactive playground.
Detailed Explanation
A CSS rule consists of a selector that targets which HTML elements to style (e.g. `h1`, `.button`, `#hero`), followed by a declaration block inside curly braces `{}`. Inside, each declaration specifies a CSS property (like `color`, `font-size`, `margin`) followed by a colon `:` and the desired value, ending with a semicolon `;`.
Syntax Reference
CSS Syntax
selector {
property: value;
another-property: value;
}Interactive Live Playground
Spacious side-by-side workspace: Edit code on the left and see immediate live execution on the right.
Introduction to CSS Code Sandbox
Edit code on the left and see live output rendering on the right.
CSS Editor53 lines
Line-by-Line Breakdown
selector { ... }Targets the HTML elements (by tag, class, or id) to receive the styles.color: #059669;Sets the foreground text color using a hex color code or rgb/hsl/oklch.padding: 32px 24px;Adds internal space between the card's content and its border.border-radius: 16px;Curves the corners of the box smoothly.Real-World Production Example
How modern web interfaces use CSS classes and pseudo-classes to build interactive pill components.
<!-- HTML -->
<div class="badge">🔥 Hot Release</div>
/* CSS */
.badge {
display: inline-flex;
align-items: center;
gap: 8px;
background: #ecfdf5;
color: #059669;
border: 1px solid #a7f3d0;
padding: 8px 16px;
border-radius: 9999px;
font-weight: 600;
font-size: 14px;
cursor: pointer;
transition: transform 0.15s ease;
}
.badge:hover {
transform: scale(1.05);
}
Common Mistakes & Gotchas
× Forgetting the semicolon at the end of a CSS declaration.
→ Fix: Every declaration must end with a semicolon `;`, otherwise subsequent properties will fail to parse.
× Confusing `margin` (outer space) with `padding` (inner space).
→ Fix: Remember: Padding is inside the border, Margin pushes neighboring elements outside the border.
Best Practices & Accessibility
- ✓Use external stylesheets with class selectors for reusable, scalable, and maintainable styling.
- ✓Keep CSS specificities low and predictable to avoid messy `!important` overrides.
- ✓Use relative units like `rem` and `em` for scalable typography and responsive spacing.
Browser Compatibility: CSS is universal across all modern and legacy web browsers.
Knowledge Check
Q1. Which CSS property is used to change the background color of an element?
Q2. How do you select an element with class name 'card' in CSS?
Hands-on Exercise
Style a Button with Emerald Accent
Write CSS to give a button a green background, white text, 10px of padding, and rounded corners.
Exercise Instructions:
- Select the `.btn` class.
- Set `background-color: #059669;`.
- Set `color: white;`.
- Set `padding: 10px 20px;` and `border-radius: 8px;`.
Your HTML Solution1 line
Your CSS Solution4 lines
Expected Outcome: A styled button with emerald green background and smooth rounded corners.