Media Queries
Media queries apply CSS rules only when specific conditions are met, such as a minimum or maximum viewport width.
They are the core tool for adapting layouts to different screen sizes.
Media queries apply CSS rules only when specific conditions are met, such as a minimum or maximum viewport width.
They are the core tool for adapting layouts to different screen sizes.
/* Mobile base (default) */
.nav { display: none; }
/* Tablet and up */
@media (min-width: 768px) {
.nav { display: flex; }
.hero { font-size: 2rem; }
}
/* Desktop */
@media (min-width: 1200px) {
.hero { font-size: 3rem; }
}
Use min-width (mobile-first) media queries — they result in cleaner, more performant CSS.