🌐Media Query
Also known as CSS Media Query, @media, Media Queries
A CSS rule that only works when a test is true, like a wide screen.
Think of it like
Think of it like a coat rule. If it is cold out, wear the big coat. If not, a jacket will do.
Example
Emma's shop shows one column of products on a phone. At 768 pixels wide and up, a media query makes it three.
Why it matters
One page has to work on a phone and a big screen. Media queries are how a page changes shape to fit.
Definition
Example code
css
@media (min-width: 768px) {
.products { grid-template-columns: repeat(3, 1fr); }
}Common mistake
Key takeaways
- 1Only when true. The styles wait for the test to pass.
- 2Width is the usual test. Change the layout as the screen grows.
- 3Other tests too. Dark mode, print and less motion.