89. Horizontal vs. Vertical Viewport Orientation
Media queries can target device orientation, allowing you to optimize a layout when a user rotates their phone or tablet.
The orientation Feature
This feature checks whether the viewport height is greater than or less than the viewport width.
portrait: The viewport height is greater than or equal to the viewport width (a typical phone holding position).landscape: The viewport width is greater than the viewport height.
css /* Styles apply when the device is held horizontally / @media (orientation: landscape) { / Maximize usage of horizontal space / .main-section { column-count: 2; / Split content into two columns */ } }
/* Styles apply when the device is held vertically / @media (orientation: portrait) { / Prioritize vertical stacking */ .main-section { column-count: 1; } }
Note: Orientation queries are often combined with width queries (e.g., (min-width: 400px) and (orientation: landscape)) to target specific device capabilities.