Orientation Lock

Chris Coyier on
@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.

  • Akhil
    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.

  • nicola
    Permalink to comment#

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

  • no thanks

    Easy solve… just add height: 100vw;

  • Zeb Oss
    Permalink to comment#

    How to disable it? My phone which is OPPO F1 Plus won’t rotate anymore even if I trun the screen rotation on. TIA for answers.

  • whispers8021
    Permalink to comment#

    A coder implemented this onto my site, and I don’t want it there. How do I remove this? which file do I look in to find it so I can delete it?

  • gentlemedia

    I have no succes with this in Safari iOS 12.2

  • Federico Madoery

    I have no succes with this in Chrome Mobile – Any recent change?

  • Ray

    Wonderful! But how can I do it if: transform: rotate(90deg)?

  • David P
    Permalink to comment#

    max-width needs to be 895px or more for a Pixel 4a phone.

  • David P
    Permalink to comment#

    max-width needs to be 895px or more for a Pixel 4a phone.

    Why is min-width needed?

    What about touchscreen laptops that choose 640×480?

    Is it possible in a media query to specify width > height?

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant