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.
Syntax
The orientation
feature is specified as a keyword value chosen from the list below.
Keyword values
portrait
- The viewport is in a portrait orientation, i.e., the height is greater than or equal to the width.
landscape
- The viewport is in a landscape orientation, i.e., the width is greater than the height.
Examples
HTML
<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
CSS
body {
display: flex;
}
div {
background: yellow;
}
@media (orientation: landscape) {
body {
flex-direction: row;
}
}
@media (orientation: portrait) {
body {
flex-direction: column;
}
}
Result
Specifications
Specification | Status | Comment |
---|---|---|
Media Queries Level 4The definition of 'orientation' in that specification. | Candidate Recommendation | No change. |
Media QueriesThe definition of 'orientation' in that specification. | Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
orientation media feature
|
Chrome
Full support 3 |
Edge
Full support 12 |
Firefox
Full support 2 |
IE
Full support 9 |
Opera
Full support 10.6 |
Safari
Full support 5 |
WebView Android
Full support ≤37 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 11 |
Safari iOS
Full support 4.2 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
orientation by Mozilla Contributors is licensed under CC-BY-SA 2.5.