CHAPTER 09
Beginner
CSS Responsive Design and Media Queries
Updated: May 10, 2026
5 min read
# Responsive Design & Media Queries
1. Introduction
Your website will be viewed on massive 4K monitors and tiny 4-inch smartphones. Responsive Design is the practice of building websites that automatically adapt their layout to fit the screen size.2. Learning Objectives
-
Understand the
<meta viewport>tag.
-
Write Media Queries using
@media.
- Implement a Mobile-First design strategy.
-
Use fluid units (
vw,vh,%).
3. Detailed Explanations
The Viewport Meta Tag
Always include this in your HTML<head>. It tells mobile devices NOT to zoom out and pretend to be a desktop computer.
html
Media Queries
Media queries act like "if statements" for CSS. They apply specific styles only when the browser window matches a condition (like width).
css
Mobile-First vs Desktop-First
-
Mobile-First (Recommended): Write your base CSS for mobile. Use
@media (min-width)to add complexity as the screen gets larger.
-
Desktop-First: Write for desktop, use
@media (max-width)to squash it down for mobile.
Responsive Images
Images will overflow their containers and cause horizontal scrolling if not handled.
css
4. Mini Project: Responsive Portfolio Grid
Let's build a layout that is 1 column on mobile, 2 columns on tablets, and 3 columns on desktops.
html
css
5. MCQs
Q1: Which @media rule is used in a mobile-first workflow? A)@media (max-width)
B) @media (min-width)
C) @media (mobile)
D) @media (screen-size)
*Answer: B*
6. Summary
Responsive design is mandatory. Always start by writing CSS for small screens, test your layout, and then use@media (min-width: ...) to add columns and adjust typography for tablets and desktops.