The orientation media feature detects whether the viewport is portrait (tall) or landscape (wide). Adapt layouts when users rotate phones or resize browser windows.
01
@media
Media query.
02
portrait
Tall viewport.
03
landscape
Wide viewport.
04
Mobile
Rotate device.
05
vs ratio
aspect-ratio.
06
+ width
Combine queries.
Fundamentals
Introduction
When you hold a phone upright, the screen is in portrait orientation — height is greater than width. Rotate it sideways and you get landscape — width is greater than height.
The @media (orientation) feature lets CSS respond to that change instantly. It is one of the most practical media queries for mobile and tablet design.
Definition and Usage
Write @media (orientation: portrait) for tall viewports or @media (orientation: landscape) for wide viewports. Combine with min-width when you only want landscape rules on larger screens.
💡
Beginner Tip
Resize your browser window taller than it is wide to trigger portrait, or wider than tall for landscape. On a phone, simply rotate the device to test.
Foundation
📝 Syntax
Use portrait or landscape inside an @media rule:
syntax.css
/* Viewport is taller than wide */@media(orientation:portrait){/* Portrait styles */}/* Viewport is wider than tall */@media(orientation:landscape){/* Landscape styles */}
Accepted Values
portrait — Viewport height is greater than width (phone held upright, tall browser window).
landscape — Viewport width is greater than height (phone rotated sideways, wide browser window).
Portrait vs Landscape
portrait height > width
landscape — width > height
orientation vs aspect-ratio
(orientation: landscape) Simple wide-vs-tall check. Matches any viewport where width exceeds height.
(min-aspect-ratio: 16/9) Matches specific ratios. Finer control for widescreen or square layouts.
Content in both orientations — Never hide essential content in one orientation.
Touch targets — Keep buttons at least 44×44px in all orientations.
Reflow — Support zoom and text scaling without horizontal scroll.
Focus order — Tab order should make sense in portrait and landscape.
Reduced motion — Avoid disorienting layout animations on rotation.
🧠 How orientation Works
1
Viewport dimensions change
User rotates device or resizes the browser window.
Resize
2
Browser compares width vs height
Determines portrait or landscape.
Compare
3
@media rules apply
Matching orientation blocks update layout, colors, and navigation.
Apply
=
📱
Rotation-ready UI
Layout adapts smoothly when the viewport shape changes.
Compatibility
🖥 Browser Compatibility
The orientation media feature is universally supported in modern browsers on mobile, tablet, and desktop.
✓ Baseline · Universal support
Portrait & landscape queries
Works in Chrome, Firefox, Safari, Edge, and Opera.
99%Global support
orientation media feature99% supported
Bottom line:orientation is production-ready. Combine with min-width for robust responsive layouts across devices.
Wrap Up
🎉 Conclusion
The orientation media feature is one of the most practical tools for responsive design. With portrait and landscape, you can adapt layouts when users rotate phones or resize browser windows.
Use it for navigation, galleries, and hero sections that should look different tall vs wide. Pair with width breakpoints and keep essential content accessible in every orientation.
Use these points when building rotation-aware layouts.
5
Core concepts
P01
portrait
Tall viewport.
Value
L02
landscape
Wide viewport.
Value
📱03
Rotate
Mobile UX.
Use case
+W04
min-width
Combine.
Pattern
🌐05
99% support
Universal.
Compat
❓ Frequently Asked Questions
The orientation media feature matches when the viewport is in portrait mode (taller than wide) or landscape mode (wider than tall). Use @media (orientation: portrait) or @media (orientation: landscape) to adapt layouts when users rotate their phone or resize the browser.
Two values: portrait (viewport height is greater than width) and landscape (viewport width is greater than height).
orientation uses simple portrait/landscape keywords based on whether height or width is larger. aspect-ratio matches specific width-to-height ratios like 16/9 or 4/3 with min/max variants for finer control.
Use it for mobile layouts that change when the device rotates, video players that go full-width in landscape, navigation that switches between stacked and horizontal, and any UI that should adapt to tall vs wide viewports.
Yes. The orientation media feature is supported in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera on phones, tablets, and desktops.