What You'll Learn
You'll learn how to write media queries that target specific viewport dimensions using width, height, min-width, max-width, min-height, and max-height features.
Understanding Width and Height Media Features
When you write responsive designs, you need to target different screen sizes. Media queries let you check the actual dimensions of the browser viewport and apply styles accordingly.
Think of these features as questions you ask the browser: "Are you at least this wide?" or "Are you shorter than this height?"
The Six Dimension Features
width- Exact viewport width (rarely used)height- Exact viewport height (rarely used)min-width- Viewport is at least this widemax-width- Viewport is no wider than thismin-height- Viewport is at least this tallmax-height- Viewport is no taller than this
Practical Examples
/* Apply styles when viewport is at least 768px wide */
@media (min-width: 768px) {
.container {
max-width: 1200px;
}
}
/* Apply styles when viewport is 600px or narrower */
@media (max-width: 600px) {
.sidebar {
display: none;
}
}
/* Target tall screens */
@media (min-height: 800px) {
.hero {
height: 100vh;
}
}
/* Combine width AND height */
@media (min-width: 1024px) and (min-height: 768px) {
.full-screen-layout {
display: grid;
}
}
Most Common Pattern
You'll typically use min-width for mobile-first design (starting small and adding complexity as screens grow) or max-width for desktop-first approaches.
Key Takeaway: Width and height media features let you target viewport dimensions precisely using min-* and max-* prefixes to create responsive breakpoints based on screen size.