Kinda Code
Home/HTML & CSS/Tailwind CSS: How to Detect Device Orientation

Tailwind CSS: How to Detect Device Orientation

Last updated: June 04, 2022

If a user is viewing your website on a mobile phone or an Android tablet or an iPad, you can determine whether the device’s orientation is portrait or landscape using Tailwind CSS’s landscape and portrait modifiers. The concrete example below demonstrates how to do it.

Screenshots

Portrait:

Landscape:

The code:

<body class="w-screen h-screen flex justify-center items-center bg-purple-700">
    <!-- This heading is hidden in portrait mode and only be shown in landscape mode-->
   <h1 class="portrait:hidden text-6xl text-white">Landscape mode</h1>

   <!-- This heading is hidden in landscape mode and only be shown in protrait mode -->
   <h1 class="landscape:hidden text-6xl text-white">Portrait mode</h1>
</body>

That’s it. Further reading:

You can also check out our CSS category page for the latest tutorials and examples.