Media queries apply CSS conditionally based on device characteristics — most often the viewport width — letting one stylesheet adapt to phones, tablets, and desktops.
{ : ; }
(: ) {
{ : ; : grid; : fr fr; }
}
(: ) {
{ : fr fr fr; }
}
Media queries apply CSS conditionally based on device characteristics — most often the viewport width — letting one stylesheet adapt to phones, tablets, and desktops.
{ : ; }
(: ) {
{ : ; : grid; : fr fr; }
}
(: ) {
{ : fr fr fr; }
}
/* ✅ mobile-first: base = mobile, layer on enhancements as it gets wider */
@media (min-width: 768px) { ... }
/* desktop-first: base = desktop, override down for smaller screens */
@media (max-width: 767px) { ... }
Mobile-first (min-width) is generally preferred: you write simple base styles for small screens, then progressively add complexity for larger ones. This tends to produce cleaner, lighter CSS and matches how content reflows.
@media (max-width: 600px) { } /* small screens */
@media (orientation: landscape) { } /* device orientation */
@media (prefers-color-scheme: dark) { } /* user wants dark mode */
@media (prefers-reduced-motion: reduce) { } /* user dislikes animation — accessibility */
@media print { } /* print stylesheet */
prefers-reduced-motion and prefers-color-scheme respond to user preferences, not screen size — important for accessibility and theming.
@media (min-width: 768px) and (max-width: 1023px) { /* tablets only */ }
Media queries respond to the viewport; the newer container queries (@container) respond to a parent element's size — better for truly reusable components. They complement media queries rather than replace them.
Media queries are the foundation of responsive design — adapting layout, spacing, and columns to screen size.
The mobile-first min-width approach keeps CSS manageable, and preference queries (prefers-reduced-motion, prefers-color-scheme) extend responsiveness to accessibility and theming.