Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Media Queries and Features

The orientation media feature

Reference for the CSS orientation media feature: portrait versus landscape viewports, how it is decided from width and height, examples and common mistakes.

The orientation media feature tells you whether the viewport is taller than wide (portrait) or at least as wide as tall (landscape). It is decided only by the viewport's width and height, not by how the device is physically held, so it also changes when you resize a desktop window.

CSS
@media (orientation: landscape) {
  .gallery {
    flex-direction: row;
  }
}

Try it

Resize the preview, or open it in a window that is taller than wide, and the label and color change.

Portrait or landscape

Syntax

CSS
@media (orientation: portrait) { /* height is greater than width */ }
@media (orientation: landscape) { /* width is greater than or equal to height */ }

It is a discrete media feature, evaluated against the viewport.

Values

Value Description
portrait The viewport height is greater than its width.
landscape The viewport width is greater than or equal to its height.

A square viewport counts as landscape.

Usage notes

  • It is about the viewport, not the device. A phone held upright inside a split-screen layout can report landscape. A narrow desktop window reports portrait.
  • Width is usually the better question. Most layout changes depend on available space, which is better expressed with width or a container query. Use orientation when the shape of the screen itself matters, such as a full-screen hero image or a video player.
  • Both values cover every case. You can write one base layout and override only for the other orientation.
  • Related feature. aspect-ratio gives you finer control than the two-way split.
  • Keyboard on mobile. On some devices opening the on-screen keyboard shrinks the viewport enough to flip it from landscape to portrait, which can cause surprising layout jumps.

Browser support

Supported in every browser.