CSS height Media Feature

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

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.

Deprecated device-height

Do not use device-height / min-device-height / max-device-height. Query the viewport with height instead.

CSS Syntax

syntax.css
@media (height | min-height | max-height: <length>) { … }

Modern range syntax also works where supported: @media (height >= 40rem).

Feature Values

FormDescriptionTry it
min-heightViewport is at least this tall (taller windows)Try it
max-heightViewport is at most this tall (short screens)Try it
heightExact viewport height (rarely useful alone)Try it
RangeCombine min and max, or use height >= …Try it

How to Use height

Design for a typical height first, then adjust for short or tall viewports.

  1. Ship a layout that works at a common desktop or phone height.
  2. Use @media (max-height: …) to tighten spacing on short windows.
  3. Use @media (min-height: …) to expand heroes or side panels when there is room.
  4. Combine with width or orientation when both axes matter.
PieceRequired?Role
@mediaYesWraps the query
Length valueYesBreakpoint size (px, em, rem, …)
min- / max-UsualRange matching instead of exact height
Base stylesYesLook correct before any query matches

Live Preview

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: 500px min-height: 501px

Checking…

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;
  }
}
Try It Yourself

How It Works

  1. Set a base. Coral is the default for shorter windows.
  2. Add min-height. The query matches from 40rem upward.
  3. Enhance. Blue applies when there is more vertical room.
  4. Tall-first enhance. Useful for heroes and spacious dashboards.

Example 2 — max-height for Short Screens

Apply a compact tweak only when the viewport is short.

CSS
p {
  background: #dbeafe;
}

@media (max-height: 500px) {
  p {
    background: #fecaca;
  }
}
Try It Yourself

How It Works

  1. Default for taller screens. Blue is the starting look.
  2. Cap with max-height. The query is true at 500px and below.
  3. Override on short. Coral marks the compact layout.
  4. Common use. Landscape phones and short laptop windows.

Example 3 — Height Range

Target a band of heights with both min and max.

CSS
p {
  background: #e2e8f0;
}

@media (min-height: 400px) and (max-height: 700px) {
  p {
    background: #bbf7d0;
  }
}
Try It Yourself

How It Works

  1. Keep a default. Gray applies outside the target band.
  2. Join with and. Both min and max must match.
  3. Hit the middle. Green appears from 400px through 700px tall.
  4. Optional modern form. @media (400px <= height <= 700px) means the same where supported.

Edge Cases & Pitfalls

Viewport height queries are easy to confuse with element sizing.

vs property

Media feature ≠ height property

@media (min-height: 600px) checks the window. height: 600px sizes a box.

exact

Exact height: is brittle

@media (height: 360px) only matches that exact size. Prefer min- / max- ranges.

device

Skip deprecated device queries

device-height reflects hardware, not layout. Use viewport height.

mobile

URL bars change height

On mobile browsers, chrome can grow or shrink the visual viewport. Prefer ranges over razor-thin exact values.

pair

Often pair with width

Many layouts need both axes. Combine with width or orientation.

Browser Support

height is a browser media feature. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

height

min-height, max-height, and height media features have been interoperable across browsers for years (Baseline since about July 2015).

99% All modern browsers
Google Chrome All
Full
Mozilla Firefox All
Full
Apple Safari All
Full
Microsoft Edge All
Full
Opera All
Full
Samsung Internet All
Full
Internet Explorer 9+
Full
@media (height) Universally supported

Bottom line: Safe for production. Prefer min-height / max-height ranges; avoid deprecated device-height.

Key Takeaways

  • 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.

Next: hover

Detect whether the primary input can hover with the hover media feature.

hover tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful