<vetted />
Frontend
Junior
Question 1 of 6

How do you approach making a website work well on all screen sizes?

Quick Answer

Use mobile-first CSS with media queries, flexible layouts with Flexbox/Grid, relative units, and test on real devices.

Detailed Answer7 paragraphs

Responsive design ensures your site works on any device. A systematic approach makes this manageable.

Mobile-first CSS writes base styles for small screens, then adds complexity for larger ones. This forces you to prioritize content and often results in cleaner CSS. Start with max-width: 100% on images and containers, stack elements vertically, then add columns for wider screens.

Flexbox handles one-dimensional layouts (rows or columns). It's perfect for navigation, card layouts, and centering. flex-wrap: wrap handles overflow gracefully. Grid handles two-dimensional layouts and is excellent for page-level structure and complex arrangements.

Use relative units. rem for typography (respects user font preferences), percentages or viewport units for layout dimensions. Avoid fixed pixel widths for containers—they break on different screens.

Media queries adapt styles at breakpoints: @media (min-width: 768px) { }. Choose breakpoints based on your design, not specific devices. Common ranges: mobile (~320-480px), tablet (~768px), desktop (~1024px+), but let your content guide you.

Container queries (newer CSS) apply styles based on parent container width rather than viewport. Better for component libraries where components need to adapt regardless of where they're placed.

Test on real devices when possible. Emulators miss touch interactions, actual performance, and rendering quirks. Use browser DevTools for quick checks, but verify on physical devices for shipping.

Key Takeaway

Use mobile-first CSS with media queries, flexible layouts with Flexbox/Grid, relative units, and test on real devices.

Ace your interview

Ready to Land Your Dream Job?

Join our network of elite AI-native engineers.