Table of Contents
- What is Responsive Design?
- Why Responsive Design Matters
- Introduction to Media Queries
- Media Query Syntax Explained
- Common Breakpoints and Devices
- Responsive Units (%, em, rem, vh, vw)
- Writing Mobile-First CSS
- Combining Media Queries with Flexbox & Grid
- Best Practices in Responsive Design
- Summary
1. What is Responsive Design?
Responsive design is the approach of creating web pages that look and function well on all screen sizes, from mobile phones to desktop monitors. Instead of creating separate layouts for each device, you use flexible grids, images, and CSS media queries to adjust the design dynamically.
2. Why Responsive Design Matters
- Mobile-first world: Over 60% of web traffic comes from mobile devices.
- Improved UX: Users stay longer and interact more with adaptable layouts.
- SEO benefit: Google considers mobile-friendliness a ranking factor.
- Consistency: Provides a seamless experience across devices.
3. Introduction to Media Queries
Media queries in CSS allow you to apply styles conditionally, depending on:
- Screen size
- Device type
- Orientation (landscape or portrait)
- Resolution
They are the cornerstone of responsive design.
4. Media Query Syntax Explained
Basic Syntax
@media (condition) {
/* CSS rules here */
}
Example: Adjusting for screens smaller than 768px
@media (max-width: 768px) {
.nav {
flex-direction: column;
}
}
Combining Conditions
@media (min-width: 768px) and (max-width: 1024px) {
/* tablet-specific styles */
}
5. Common Breakpoints and Devices
There are no strict rules, but these are popular breakpoints used in practice:
Device | Width Range | Example |
---|---|---|
Extra small | < 576px | Phones |
Small | 576px – 767px | Larger Phones |
Medium | 768px – 991px | Tablets |
Large | 992px – 1199px | Small Laptops |
Extra large | 1200px and up | Desktops |
You can tailor your design to these categories, or create your own based on analytics.
6. Responsive Units (%, em, rem, vh, vw)
Choosing the right units makes a huge difference.
Unit | Description | Use Case |
---|---|---|
% | Relative to parent | Fluid layouts |
em | Relative to parent font-size | Padding, spacing |
rem | Relative to root font-size | Typography consistency |
vh | 1% of viewport height | Full-screen sections |
vw | 1% of viewport width | Responsive width elements |
Example: Full-screen hero
.hero {
height: 100vh;
width: 100vw;
}
7. Writing Mobile-First CSS
A mobile-first approach means writing your base CSS for small screens first, and then progressively enhancing it for larger screens.
Example
/* Base styles for mobile */
.container {
flex-direction: column;
}
/* Desktop enhancement */
@media (min-width: 992px) {
.container {
flex-direction: row;
}
}
This ensures performance and usability on the most constrained devices first.
8. Combining Media Queries with Flexbox & Grid
You can change layout behaviors based on screen size:
Example: Switching Flex Direction
.cards {
display: flex;
flex-direction: column;
}
@media (min-width: 768px) {
.cards {
flex-direction: row;
}
}
Example: Adjusting Grid Columns
.grid {
display: grid;
grid-template-columns: 1fr;
}
@media (min-width: 768px) {
.grid {
grid-template-columns: repeat(3, 1fr);
}
}
9. Best Practices in Responsive Design
✅ Use mobile-first development.
✅ Avoid fixed widths; prefer %
, vw
, or flex-grow
.
✅ Test on real devices or responsive mode in DevTools.
✅ Don’t hide content unnecessarily—restructure instead.
✅ Use min-width
media queries for predictable overrides.
✅ Pair media queries with container queries (upcoming spec) for component-based responsiveness.
10. Summary
Media queries empower you to build websites that adapt to any screen size, ensuring your content is always accessible, legible, and functional. Paired with responsive units, flexible layouts, and mobile-first principles, they are a critical tool in modern web development.
As web usage diversifies across devices, mastering media queries is no longer optional—it’s essential.