Media Query
ELI5 — The Vibe Check
A media query is a CSS if-statement based on screen conditions. 'If the screen is narrower than 768px, apply these styles.' You can check width, height, orientation, dark mode preference, and more. The backbone of responsive design.
Real Talk
A media query is a CSS at-rule (@media) that applies styles conditionally based on device characteristics such as viewport width, height, orientation, resolution, or color scheme preference. Media queries are fundamental to responsive design and are now also usable in JavaScript via window.matchMedia().
Show Me The Code
@media (max-width: 768px) {
.nav { flex-direction: column; }
.sidebar { display: none; }
}
@media (prefers-color-scheme: dark) {
body { background: #1a1a1a; color: #fff; }
}
When You'll Hear This
"Write a media query to hide the sidebar on mobile." / "Use prefers-color-scheme media query for automatic dark mode."
Related Terms
Breakpoint
A breakpoint is like a 'pause game' button you place on a specific line of code.
CSS (Cascading Style Sheets)
CSS is the makeup and wardrobe for your HTML skeleton. It decides what color everything is, how big things are, and where stuff goes on the page.
Mobile First
Mobile first means you design for the smallest screen first, then add styles as screens get bigger.
Responsive Design
Responsive design means your website looks good on EVERY screen size — from a tiny phone to a giant 4K monitor.
Viewport
The viewport is the visible area of a webpage in the user's browser window. It changes depending on the device — small on a phone, huge on a 4K monitor.