The height media feature tests the viewport height (or the page box for paged media). It is a range feature, so you also get min-height and max-height variants.
Use it when vertical space matters—compact chrome on short windows, taller heroes on tall screens. It is not the same as the height property, which sizes one element.
Baseline · Widely available.
Not deprecated. Core height / min-height / max-height media queries work in all modern browsers.
Deprecateddevice-height
Do not use device-height / min-device-height / max-device-height. Query the viewport with height instead.
Resize this window’s height. The sample uses real @media (max-height: 500px) and (min-height: 501px) rules. The note shows the current viewport height from JavaScript.
Viewport height
Coral at 500px and below. Blue at 501px and up.
Height breakpoints
Resize height to switch styles
max-height: 500pxmin-height: 501px
Checking…
Code
CSS Examples
Each snippet focuses on the height media feature. Use Try It Yourself for a live editor—resize the preview pane height.
Example 1 — min-height for Tall Viewports
Enhance styles when the viewport is tall enough.
CSS
p {
background: #fecaca;
}
@media (min-height: 40rem) {
p {
background: #dbeafe;
}
}
Role: query viewport height for vertical breakpoints.
Forms:min-height, max-height, and exact height.
Pattern: tighten with max-height; expand with min-height.
Tip: prefer ranges; never device-height.
One line:height media queries adapt CSS to vertical viewport space—size elements with the height property separately.
Frequently Asked Questions
It tests the viewport height (or the page box for paged media). Use it inside @media to change styles when the window is short or tall.
min-height matches when the viewport is at least that tall. max-height matches when it is at most that tall. They are the range prefixes of height.
The media feature queries the viewport for conditional CSS. The height property sets the height of one element.
For short laptop windows, landscape phones, compact headers, or heroes that should shrink when vertical space is limited. Pair with width queries when both axes matter.
No. device-height is deprecated. Query the viewport with the height media feature instead.
No. It is a CSS media feature evaluated by the browser, not a Node.js or server runtime feature.