Orientation of mobile and tablets. source: http://khef.co

If you are stuck with screen lock complications for web application then you are at right place.

It is not recommended to force the user to lock screen in one screen orientation. But locking screen orientation is a necessity in some cases like - gaming, video contents, PDF contents.

We have three practical ways to achieve this:-

  1. Using pure JavaScript API designed for modern browsers.
  2. Using complete CSS code.
  3. giving user a message to use in portrait mode.

Lets break these methods one by one.

  1. Using pure JavaScript API:

This method has two restrictions:

  1. Not supported in safari in iPhone.

Amit Kumar

Engineer, full-stack developer. learning and sharing is the only hobby.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store