The orientation CSS media feature can be used to test the orientation of the viewport (or the page box, for paged media).

Note: This feature does not correspond to device orientation. Opening the soft keyboard on many devices in portrait orientation will cause the viewport to become wider than it is tall, thereby causing the browser to use landscape styles instead of portrait.


The orientation feature is specified as a keyword value chosen from the list below.

Keyword values

The viewport is in a portrait orientation, i.e.,  the height is greater than or equal to the width.
The viewport is in a landscape orientation, i.e., the width is greater than the height.



<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>


body {
  display: flex;

div {
  background: yellow;

@media (orientation: landscape) {
  body {
    flex-direction: row;

@media (orientation: portrait) {
  body {
    flex-direction: column;



Specification Status Comment
Media Queries Level 4
The definition of 'orientation' in that specification.
Candidate Recommendation No change.
Media Queries
The definition of 'orientation' in that specification.
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
orientation media featureChrome Full support YesEdge ? Firefox Full support 2IE Full support 9Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4Opera Android ? Safari iOS ? Samsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Last updated by: mdnwebdocs-bot,