Testing Responsive Designs
Responsive designs must be tested across multiple screen sizes and devices. Learn how to use browser DevTools for responsive testing, common viewport sizes to check, and the most frequent responsive design bugs.
Testing Techniques
- Chrome DevTools Device Mode — F12 → toggle device toolbar (Ctrl+Shift+M). Simulates any screen size
- Preset devices — DevTools includes iPhone, iPad, Pixel, Galaxy presets with accurate dimensions
- Drag to resize — Drag the viewport edges in DevTools to test at any arbitrary width
- Key widths to test — 320px (small phone), 375px (iPhone), 768px (iPad), 1024px (laptop), 1440px (desktop)
- Test orientation — Rotate between portrait and landscape in DevTools. Layouts often break in landscape
- Real device testing — DevTools simulation isn't perfect. Test on actual phones for touch, scroll, and performance
- Common bugs — Horizontal scroll (check overflow), text too small (use rem/clamp), touch targets too small (min 44px)
Debugging Responsive Issues
/* Common responsive bugs and fixes */
/* BUG 1: Unwanted horizontal scroll */
/* Find the culprit: */
* { outline: 1px solid red !important; }
/* Fix: overflow-x: hidden on body (temporary) */
/* Real fix: find the overflowing element */
/* BUG 2: Content too small on mobile */
/* Add the viewport meta tag in HTML <head>: */
/* <meta name="viewport" content="width=device-width, initial-scale=1"> */
/* Without this tag, mobile browsers render at desktop width! */
/* BUG 3: Fixed-width elements breaking layout */
/* Bad */
.sidebar { width: 300px; } /* Overflows on 320px screen! */
/* Good */
.sidebar { width: min(300px, 100%); }
/* BUG 4: Images overflowing containers */
img { max-width: 100%; height: auto; }
/* BUG 5: Horizontal padding causing overflow */
.box { width: 100%; padding: 20px; } /* 100% + 40px! */
/* Fix: Always use box-sizing: border-box */
* { box-sizing: border-box; }Tip
The 'outline all elements' debug trick (* { outline: 1px solid red !important }) instantly reveals which element is causing horizontal scroll or unexpected overflow on mobile. Run it in DevTools console, scroll right, and the culprit will be visible. Remove it after debugging.
Mobile-first: start with mobile styles, enhance with min-width queries
Common Mistake
Only testing in Chrome on desktop. Mobile Safari and Android Chrome have different rendering quirks, especially for: position: sticky (requires overflow: auto context), dvh units, and custom scrollbars. Always test on at least 2 real devices before declaring a responsive design done.
Practice Task
Run a responsive audit on any page: (1) Open DevTools and test at 320px, 375px, 768px, 1024px, 1440px, (2) Use the outline trick to find overflowing elements, (3) Check that all text is readable (min 14px), all buttons are tappable (min 44px height), and no horizontal scroll exists on mobile.
Quick Quiz
Key Takeaways
- Responsive designs must be tested across multiple screen sizes and devices.
- Chrome DevTools Device Mode — F12 → toggle device toolbar (Ctrl+Shift+M). Simulates any screen size
- Preset devices — DevTools includes iPhone, iPad, Pixel, Galaxy presets with accurate dimensions
- Drag to resize — Drag the viewport edges in DevTools to test at any arbitrary width