Rotate a phone and the page changes shape completely. The viewport goes from tall and narrow to wide and short, closer to a cinema screen than to a page. Most responsive work concentrates on width, so the rotated phone gets the roomier layout its width earns, squeezed into a strip of height where a hero fills the screen and navigation eats the rest.

Orientation queries exist for exactly this case: CSS that applies only when the viewport is wider than it is tall, or the reverse. This guide explains what the condition really tests, how to pair it with a size limit, and how to build the combined block with the free Media Query Builder on Ovatly.

Contents

  • Quick answer
  • What orientation actually measures
  • Why landscape phones are a special case
  • Pairing orientation with a second condition
  • How to build an orientation query, step by step
  • Worked example: taming a hero section on rotated phones
  • What people actually restyle in landscape
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

An orientation media query tests the viewport's shape: landscape matches when the viewport is wider than it is tall, portrait when it is taller than it is wide. Used alone it matches desktop monitors too, so pair it with a size condition such as a max height, joined by and. The Media Query Builder lets you set an orientation alongside width and height limits, and emits a combined @media block. The condition decides when your rules apply; the rules themselves are your own CSS inside the block.

What orientation actually measures

Orientation sounds like a property of the device, and it is not. It is a property of the viewport, the rectangle your page renders into. Wider than tall means landscape; taller than wide means portrait. A perfectly square viewport counts as portrait, by the way the feature is defined.

Because it follows the viewport, orientation changes without any device changing hands. Rotate a phone and the value flips; drag a desktop window from tall to wide and the same flip happens. That is why an orientation query on its own is blunt: every ordinary desktop window is landscape.

Orientation also says nothing about capability: not screen size, not touch input, not device type. It reports one fact, the shape of the box, and you combine it with size conditions until it describes the screens you mean.

Why landscape phones are a special case

A portrait phone might offer a viewport around 390 CSS pixels wide and 800 tall; rotated, roughly 800 wide and 390 tall. The width now resembles a tablet, so width breakpoints promote the layout to its tablet arrangement.

The height tells a different story: 390 CSS pixels is less than many laptops show in a half-height window. A hero designed to fill most of the screen still tries to, and a navigation bar plus that hero can consume the entire visible area, so the page looks broken even though every width rule behaved.

That mismatch, tablet width with minimal height, is the gap orientation queries fill.

Pairing orientation with a second condition

Media query conditions combine with and: every condition must be true before the block applies. That one word turns orientation from blunt to precise.

The most useful partner for landscape work is a height limit. A block like @media screen and (orientation: landscape) and (max-height: 500px) describes screens wider than tall and at most 500 CSS pixels high: rotated phones, and very little else. A monitor fails the height test; a portrait phone fails the orientation test.

A width range can do a similar job. The builder exposes all of these as fields: min and max width, min and max height, orientation, and media type. Leaving a field empty means no limit on that side. The builder also validates the obvious error, a minimum larger than its maximum, instead of emitting a block that never matches.

How to build an orientation query, step by step

  1. Open the Media Query Builder.
  2. Set the media type to screen.
  3. Set the orientation condition to landscape.
  4. Add the narrowing condition: a max height such as 500, or a max width at the top of your phone range.
  5. Copy the combined block into your stylesheet, after the base rules it adjusts.
  6. Write the landscape rules inside the block: shorter heroes, compact navigation, media sized for the height available.

Test by rotating a phone, or by resizing a desktop window until it is wide and short; the second method works because the query follows the viewport.

Worked example: taming a hero section on rotated phones

Take a landing page whose hero is most of the viewport height. On a rotated phone that hero becomes a short wall: the headline and button fit, barely, and the visitor sees nothing below until they scroll.

In the builder, choose screen, orientation landscape, and max height 500. The output follows the same shape as the builder's basic block, with the extra conditions joined by and:

@media screen and (orientation: landscape) and (max-height: 500px) {
  /* your CSS here */
}

Inside it, the rules are yours: stop tying the hero to viewport height, let it size to its content, and slim the navigation down:

@media screen and (orientation: landscape) and (max-height: 500px) {
  .hero {
    min-height: auto;
    padding: 2rem 1rem;
  }
  .site-nav {
    padding: 0.5rem 1rem;
  }
}

The builder produced a condition that matches rotated phones and almost nothing else; your CSS decided what changes there.

What people actually restyle in landscape

Three categories account for most landscape adjustments. First, anything sized from viewport height: heroes and full-screen sections, which need to relax their height rules. Second, navigation: a stacked portrait menu can become a compact horizontal bar, and a tall one may need to become a short scrollable one. Third, media: galleries and video players are often capped by height instead of width, keeping the whole control bar on screen. Columns and grids are usually absent from the list: they follow width breakpoints you already have. Orientation work is mostly about the vertical budget.

Limitations and honest tradeoffs

Orientation is a shape test, nothing more. It cannot distinguish a rotated phone from a short browser window; paired conditions narrow that gap rather than close it. Touch and pointer precision are different media features, outside what this builder covers.

The builder's presets are conventions, not standards, and orientation has no preset at all: the limit you pair with it is your call, ideally taken from your own layout and analytics. The builder also writes no CSS beyond the block wrapper and its placeholder; every restyle is hand-written.

There is a maintenance cost too. Every orientation block is a third layout state to test, alongside portrait and desktop, and sites that never test them again ship stale exceptions. Keep the blocks few and purposeful.

Common mistakes

  • Using orientation alone. A bare landscape query matches every desktop window. Pair it with a height or width limit so it means rotated phones.
  • Assuming orientation identifies the device. It identifies the viewport's shape. A resized window matches, a tablet in a stand matches, and neither is a phone.
  • Restyling everything. Landscape blocks work best as small corrections to height-hungry components, not as a rebuilt layout that contradicts your width breakpoints.
  • Testing only by rotating one phone. Viewport sizes vary. Test the boundary too: a window just above and just below your height limit.

FAQs

What does the orientation condition actually test? It tests the shape of the viewport. Landscape matches when the viewport is wider than it is tall, portrait when it is taller than it is wide. It says nothing about the device, so a resized desktop window can match too.

Why pair orientation with a height or width limit? On its own, landscape matches everything from a rotated phone to a widescreen monitor. Adding a max-height or a width range narrows the block to the short, wide screens you actually mean.

What do people usually change in landscape? The things vertical space controls: hero sections get shorter, horizontal navigation replaces stacked menus, and media gets room to use the width. The exact rules are your CSS; the query only decides when they apply.

Are the builder's presets official breakpoints? No. The presets are widely used conventions gathered from common device sizes, not standards. You can also type exact pixel widths and heights, which is usually the better fit for orientation work.

Can the builder create an invalid query? It guards the obvious trap: a minimum larger than its maximum is flagged instead of emitted. Conditions combine with 'and', so every condition set has to be true for the block to apply.

Conclusion

Orientation queries answer a question width cannot ask: not how wide is the screen, but what shape is it. Pair landscape with a height cap in the Media Query Builder and you get a block that speaks to rotated phones precisely, leaving monitors and portrait layouts untouched. For the width side of the same job, our guide to stacking layout columns on small screens covers the max-width pattern. For more guides in this series, see our Website and Webmaster Tools guides, which pair each technique with the free tool that performs it.

References