Responsive Design
6 min read Quiz at the end
Media queries apply styles at specific screen widths: @media (min-width: 768px) { }. Write mobile styles first and add breakpoints for larger screens. Use relative units like %, rem, and vw for flexibility.
Responsive Design /* Mobile first */
.container { padding: 16px; }
@media (min-width: 768px) {
.container { padding: 32px; }
}
@media (min-width: 1280px) {
.container { max-width: 1200px; margin: auto; }
}
/* Responsive font size */
html { font-size: clamp(14px, 1.5vw, 18px); }
/* Flexible images */
img { max-width: 100%; height: auto; }
Topic Quiz · 5 questions
Test your understanding before moving on
1. Mobile-first means:
A. Design for desktop first
B. Write base styles for mobile, add larger screen styles with min-width media queries
C. Only support mobile
D. Ignore desktop
💡 Mobile-first: start with mobile styles, then enhance with min-width breakpoints for larger screens.
2. Which meta tag is required for responsive design?
A. <meta charset>
B. <meta name="viewport" content="width=device-width, initial-scale=1">
C. <meta http-equiv>
D. <meta name="mobile">
💡 The viewport meta tag tells mobile browsers to use the device width.
3. max-width: 100% on images does what?
A. Stretches images
B. Prevents images from overflowing their container
C. Fixes image height
D. Centers images
💡 max-width: 100% ensures images never exceed their container width.
4. Which media query targets screens wider than 768px?
A. @media (max-width: 768px)
B. @media (min-width: 768px)
C. @media screen 768px
D. @media width: 768px
💡 min-width: 768px applies styles when viewport is 768px or wider.
5. clamp() is useful for:
A. Border widths
B. Font sizes and spacing that scale between min and max values
C. Color transitions
D. Animation timing
💡 clamp(min, preferred, max) creates fluid values that scale with the viewport.
Submit answers