Responsive Web Design
A responsive website adjusts beautifully on mobile, tablet and desktop screens. In this chapter, you will learn viewport, flexible layouts, media queries and mobile-first design.
Viewport
Allows webpage to fit device width properly.
Fluid Layout
Uses flexible width instead of fixed width only.
Media Queries
Applies CSS based on screen size.
Breakpoints
Screen sizes where layout changes.
After This Chapter, You Will Understand
This chapter helps you build webpages that work smoothly on all screen sizes.
Viewport
Use viewport meta tag for mobile-friendly pages.
Fluid Width
Use %, max-width and flexible units.
Media Queries
Apply different styles at different screen sizes.
Responsive Layout
Make cards, menus and grids adapt to devices.
What is Responsive Web Design?
Responsive web design means creating websites that adjust according to the user's screen size.
1 Simple Meaning
A responsive webpage looks good and remains usable on mobile phones, tablets, laptops and desktop screens. Text, images, menus, cards and layouts should adjust automatically.
Viewport Meta Tag
The viewport meta tag tells the browser how to scale the webpage on different devices.
2 Required Meta Tag
This tag should be included in the head section of every responsive webpage.
3 Meaning
- width=device-width: page width matches device width
- initial-scale=1.0: page starts at normal zoom level
- Improves mobile display
- Prevents desktop-style shrinking on mobile
Flexible Width and Images
Responsive design uses flexible sizes instead of only fixed pixels.
Flexible Container
Element can shrink and grow with screen size.
Flexible Image
max-width: 100%;
height: auto;
}
Images should not overflow outside their container.
Responsive Cards
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
Cards automatically adjust according to available width.
Changing CSS Based on Screen Size
Media queries allow CSS to change when the screen becomes smaller or larger.
4 Basic Media Query
grid-template-columns: repeat(3, 1fr);
}
@media(max-width: 768px) {
.cards {
grid-template-columns: 1fr;
}
}
5 Common Breakpoints
| Device | Common Width |
|---|---|
| Mobile | up to 600px |
| Tablet | 601px to 992px |
| Laptop | 993px to 1200px |
| Desktop | 1200px+ |
Mobile-First Design
Mobile-first means designing for small screens first, then enhancing for larger screens.
6 Mobile-First Approach
In mobile-first CSS, the default design is for mobile screens. Then we add media queries for tablets and desktops.
.cards {
display: grid;
grid-template-columns: 1fr;
}
/* Tablet and desktop */
@media(min-width: 768px) {
.cards {
grid-template-columns: repeat(3, 1fr);
}
}
7 Responsive Checklist
- Add viewport meta tag
- Use flexible containers
- Use max-width for images
- Use media queries for layout changes
- Check readability on mobile
- Test buttons and menus on small screens
Practice Responsive Web Design
Edit media query and resize your browser to see the layout change.
Mistakes Students Should Avoid
Responsive design requires planning, testing and flexible layout choices.
Wrong Habits
- Forgetting viewport meta tag
- Using fixed width for main layout
- Not making images flexible
- Using desktop design only
- Not testing on mobile screen
Correct Habits
- Add viewport meta tag
- Use width:100% and max-width
- Use max-width:100% for images
- Use media queries for layout changes
- Test readability, spacing and buttons on mobile
Test Your Understanding
Select the correct answers and check your score.
1. Responsive web design means:
2. Which meta tag is important for mobile-friendly pages?
3. Which CSS rule applies styles based on screen size?
4. Which CSS is good for responsive images?
5. Mobile-first design means:
Remember These Points
Revise these before moving to Chapter 22.
Responsive Design
It makes webpages adjust to mobile, tablet and desktop screens.
Viewport
The viewport meta tag helps pages display properly on mobile.
Fluid Layout
Flexible width and max-width help layouts adapt.
Media Query
@media applies different CSS at different screen sizes.
Flexible Images
Use max-width:100%; height:auto; for responsive images.
Mobile First
Design for small screens first, then enhance for larger screens.