Orientation Lock

@media screen and (min-width: 320px) and (max-width: 767px) and (orientation: landscape) {
  html {
    transform: rotate(-90deg);
    transform-origin: left top;
    width: 100vh;
    overflow-x: hidden;
    position: absolute;
    top: 100%;
    left: 0;

Sent in by Andreas Gotfredsen.


  1. User Avatar
    Permalink to comment#

    I was just playing around with this but haven’t had total success. The vw and vh units still seem to refer to the original portrait orientation, so any layout done with these units breaks. Ideally, we would be able swap vw and vh when the page is rotated, but I couldn’t find any way to do that. One workaround would be to define –vw and –vh variables and set them appropriately for each orientation, but then we are stuck with the clumsy calc()/var() syntax when using them.

  2. User Avatar

    Chris, we have for it now Screen Orientation API, see https://w3c.github.io/screen-orientation/


  3. User Avatar
    Permalink to comment#

    I am getting the following error when I try to run in Google Chrome.
    Uncaught (in promise) DOMException: screen.orientation.lock() is not available on this device.

  4. User Avatar
    Permalink to comment#

    Those screen.orientation.lock() API are supported only on FF in mobile …

  5. User Avatar
    no thanks

    Easy solve… just add height: 100vw;

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.