CSS Media Queries allow websites to adapt their layouts, typography,
spacing, and components based on screen size, device capabilities,
orientation, and user preferences. Media queries are one of the
most important technologies behind Responsive Web Design.
What Are CSS Media Queries?
Media queries allow CSS styles to be applied only when specific
conditions are met. These conditions can include screen width,
height, orientation, resolution, hover support, color scheme,
reduced motion preferences, and more.
This layout adapts smoothly from mobile to desktop.
Container Queries vs Media Queries
Feature
Media Queries
Container Queries
Based On
Viewport Size
Container Size
Best For
Page Layouts
Reusable Components
Support
Universal
Modern Browsers
Media queries remain the foundation of responsive web design, while
container queries are increasingly used for component-level responsiveness.
Media Queries and Accessibility
Support reduced motion preferences.
Provide dark mode support.
Optimize touch targets for mobile users.
Ensure layouts remain usable at high zoom levels.
Improve readability across devices.
Media Queries and SEO
Media queries contribute indirectly to SEO by helping create
mobile-friendly websites that provide better user experiences.
Support responsive layouts.
Improve mobile usability.
Reduce bounce rates.
Improve engagement metrics.
Support Core Web Vitals optimization.
Enable mobile-first indexing readiness.
Common Media Query Mistakes
Creating too many breakpoints.
Using device-specific breakpoints.
Ignoring mobile-first development.
Using fixed widths.
Not testing on real devices.
Ignoring accessibility preferences.
Overwriting styles excessively.
CSS Media Query Best Practices
Use mobile-first development.
Choose content-driven breakpoints.
Use relative units where possible.
Support dark mode.
Support reduced motion.
Test across devices and orientations.
Keep media queries organized.
Use CSS Grid and Flexbox with media queries.
Optimize performance and maintainability.
Key Takeaways
Media queries enable responsive web design.
Mobile-first development is recommended.
Breakpoints should be content-driven.
Media queries support accessibility preferences.
Dark mode and reduced motion improve user experience.
Media queries are essential for modern SEO and mobile usability.
Pro Tip
Start with mobile styles first, then use
@media (min-width: ...) breakpoints to enhance layouts
for larger screens. This approach produces cleaner and more scalable CSS.