The most reliable way to avoid landscape CSS is to stop writing orientation-specific rules at all and instead design against the container or the viewport size that actually matters. If you searched for "avoid using landscape css," you likely mean one of two things: eliminating @media (orientation: landscape) rules from a stylesheet because they are brittle and hard to maintain, or avoiding the generic "landscape/portrait" framing in favor of width-based breakpoints. Both interpretations point to the same practical conclusion: orientation is a poor proxy for layout needs, and you can almost always express the same design intent with width, height, aspect ratio, or container queries. This article explains why that substitution works, when it fails, and how to rewrite the most common landscape rules you are trying to retire.
What "landscape CSS" usually refers to
In web development, landscape CSS almost always means one of these:
Media query orientation clauses, written as @media (orientation: landscape) or (orientation: portrait). Device-rotation handling, where scripts listen for orientationchange or read screen.orientation to restyle a page. Class-based orientation toggles, where JavaScript adds a class such as .is-landscape to the or element and CSS hangs styling off that class.
All three share a defining assumption: that the shape of the viewport tells you something meaningful about how the user wants content arranged. That assumption is often wrong. A desktop browser window that is slightly wider than it is tall is technically "landscape," but it may be a narrow column on a large monitor. A phone in portrait may be physically taller than a small tablet in landscape. Orientation describes proportion, not available space, and not input method, and not user intent. That mismatch is the root reason developers try to avoid it.
Why people want to avoid landscape CSS
There are legitimate maintenance problems with orientation-driven styles.
Orientation queries fight with width-based breakpoints. A typical responsive stylesheet defines breakpoints at widths like 640px, 768px, and 1024px. An orientation query cuts across those boundaries. On a phone that rotates to landscape, you can suddenly match both a narrow-width rule and a landscape rule, and the cascade resolution becomes hard to predict. Debugging "why did this element change when I rotated the phone?" is a recurring cost.
Orientation is unstable on modern devices. Foldables, tablets with keyboards, and desktop windows that users resize freely all blur the portrait/landscape divide. A Surface device in "laptop" mode may report landscape while a user has a narrow snapped window. A window narrowed on a portrait monitor may report portrait while being short and wide in practice. The query does not describe what the user sees.
Orientation does not tell you about pointers or input. The most common reason to want landscape-specific styles is to accommodate a wide, short viewport — for example, a video player, a data table, or a toolbar. But the better signal is usually available height or aspect ratio, not orientation. And touch versus mouse is a separate concern handled by hover and pointer media features.
Orientation changes are expensive to handle in JavaScript. Registering orientationchange or observing screen.orientation adds listeners that fire inconsistently across browsers, and many of them are unnecessary if CSS already responds to layout size through normal responsive techniques.
That said, avoiding landscape CSS is not an absolute rule. There are a few narrow cases where orientation genuinely carries information you cannot reconstruct from width or height alone — described later — and in those cases you should use it deliberately rather than reflexively.
Replace the orientation query with the dimension you actually care about
The core technique is simple: for every landscape rule, ask "what is this rule really trying to detect?" Almost always the answer is one of width, height, aspect ratio, or available space around a component. Then write that condition instead.
A quick reference for translating common patterns:
| What the landscape rule was doing | Better condition to write | Why it is better |
|---|---|---|
| Making content two columns when "wide" | @media (min-width: 768px) | Detects the actual space available, not the shape |
| Shrinking vertical spacing when "short" | @media (max-height: 500px) | Height is the real constraint in short viewports |
| Side-by-side layout for video players | @media (min-aspect-ratio: 16/9) | Aspect ratio captures the layout need precisely |
| Switching a component's layout | @container (min-width: 40rem) | Responds to the component's own space, not the screen |
| Adjusting for touch | @media (pointer: coarse) | Detects input type directly instead of guessing from orientation |
Each of these addresses a real condition, and each remains correct when the user resizes a desktop window or a foldable changes shape. None of them break when a device rotates, because they read the resulting dimensions directly.
Use aspect ratio when the layout genuinely depends on shape
The one case where orientation is closest to being the right tool is when the layout really does depend on whether the viewport is wider than it is tall. Even then, express the intent with aspect-ratio rather than orientation, because aspect ratio lets you ask for a specific proportion like 16:9 or 4:3, not just "wider" or "taller."
Aspect-ratio queries are well supported in modern browsers and are less ambiguous than orientation. They also let you target a specific ratio, which orientation cannot.
Use container queries for component-level behavior
Most homegrown landscape rules actually exist to make a single component fit its parent, not to respond to the device. Container queries were designed for exactly this problem. Instead of styling based on the viewport's orientation, mark the parent as a container and style the child based on its own width:
Container queries decouple a component's layout from the device entirely, which is what most landscape rules were implicitly trying to approximate. They also make components reusable in sidebars, modals, and narrow columns, where orientation would be meaningless.
Use min-width and min-height together when both matter
When a component needs a wide and short viewport — the classic landscape phone case — write both conditions together rather than reaching for orientation:
This is more explicit than orientation: landscape and, importantly, it will also match a short desktop window or a zoomed-in browser even if the device is technically portrait. The rule is written to match a layout situation, not a device posture.
Handling cases where you are forced to deal with orientation
Sometimes a legacy stylesheet, a third-party component, or a platform constraint means orientation rules already exist and you need to neutralize or override them rather than ignore them. A few tactics work.
Override orientation rules with explicit size rules. If you cannot delete a legacy @media (orientation: landscape) block, you can still place a width- or height-based rule later in the cascade to take precedence. This is a stopgap, not a fix, but it is often enough to migrate incrementally.
Audit with the media feature in DevTools. In browser developer tools you can emulate orientation, and more usefully you can toggle individual media features to find every stylesheet rule that depends on orientation. Each found rule is a candidate for replacement with a width, height, aspect ratio, or container condition. Removing them one at a time keeps the change testable.
Do not rely on JavaScript orientation classes unless you also clean them up. A script that adds .is-landscape needs to be changed, or removed entirely. The cleanest migration is to replace the class-based styling with media queries that read actual widths, then delete the class-toggling script when no rules depend on it. If some transformed layout truly needs to know the device's physical orientation — for example, a kiosk app that must lock to an aspect ratio — prefer the screen.orientation API directly in the component that needs it rather than a global class on the document.
Use prefers-reduced-motion and hover for the intent behind many landscape hacks. Frequently, developers added landscape rules to compensate for touch devices with limited vertical space. When the goal is really "this is a touch device" or "this is a hoverless pointer," the right queries are @media (pointer: coarse) and @media (hover: none). These are more accurate than orientation and do not change when the user rotates the screen.
When avoiding landscape CSS is the wrong call
There are a small number of situations where orientation is the right signal, and pretending otherwise can create bugs.
Fullscreen media players. A video player that should display edge-to-edge content sometimes genuinely needs to know the viewport shape, and an aspect-ratio query may be more direct than orientation — but if the video's native aspect ratio must be preserved regardless of viewport size, you may still need to reason about screen shape. In practice, object-fit and aspect-ratio usually do the job better than orientation. Kiosk and locked-orientation apps. If an app is designed to run in a fixed physical orientation, the real requirement is not "landscape CSS" but a locked orientation, declared in the manifest or native wrapper. Styles should then assume that orientation unconditionally rather than re-detecting it. Gaming and canvas-based experiences. A game that expects a horizontal canvas may legitimately show a "rotate your device" prompt when the viewport is tall. That check can be written with aspect ratio or max-aspect-ratio, and is one of the few places where the physical posture matters to the user experience. Accessibility-related orientation handling. Some users have device orientation locked for medical or accessibility reasons. However, this is an argument for not requiring orientation changes — a point that reinforces the general advice to avoid orientation-dependent layouts rather than a case for adding more orientation CSS.
In short, use orientation queries only when the physical posture is genuinely part of the requirement, and even then prefer a platform-level orientation lock over CSS detection.
Common traps when removing landscape CSS
Replacing every orientation rule with a width breakpoint of the same number. If the original rule only kicked in at landscape on tablets, the equivalent width breakpoint is not automatically the same pixel count. Landscape on a 768px-wide tablet means the viewport is at least 768px wide and shorter than 768px tall. Replacing it with @media (min-width: 768px) changes behavior on large desktop windows, which the original rule may not have intended to affect. Write the condition for the actual layout situation.
Forgetting short-but-wide windows. The most convincing failure of orientation-based CSS is the resizable desktop window. A user drags a window to 1000px wide and 400px tall. This is landscape by orientation, and any rule designed for landscape phones will fire, but it is also a narrow desktop window. Width-only rules will treat it as a desktop layout with too little height. Pairing width and height conditions prevents this.
Treating container queries as a drop-in replacement for every media query. Container queries respond to the container's size, which is what you want for components, but they cannot respond to the viewport itself. For page-level layout that depends on the browser window, container queries on the root element work only if you set up the root as a container, and behavior around the root container is subtle. Prefer ordinary media queries for the page frame.
Leaving the orientationchange listener in place after removing the CSS. If JavaScript previously toggled classes in response to rotation, it should be removed along with the rules. An unused listener is harmless in isolation but creates confusion during the next maintenance pass and can trigger layout reads on every rotation.
A practical migration checklist
If you are cleaning an existing codebase, this sequence works:
1: Search for orientation: landscape, orientation: portrait, orientationchange, and any class name containing "landscape" or "portrait." 2: For each match, write one sentence describing what layout problem it was solving. If the sentence is "this makes the page look right on a phone turned sideways," the real condition is a short viewport: use max-height. 3: Replace page-level rules with min-width, max-height, aspect-ratio, or combinations. Replace component-level rules with container queries. 4: Test resizing the browser window to landscape-shaped but narrow dimensions, and to portrait-shaped but wide, tall dimensions. These cases catch almost every incorrect substitution. 5: Delete orientation-related JavaScript and class toggles once no CSS depends on them. 6: Keep any genuinely orientation-dependent rule, document why it exists, and prefer a platform orientation lock where available.
The migration usually reduces the total number of media queries, because many landscape rules existed only to patch problems that width and height queries already solve.
The bottom line
Landscape CSS is a proxy for real layout conditions, and proxies drift. The direct way to stop using it is to replace each orientation rule with the condition it was standing in for: available width, available height, aspect ratio, or the size of the component's container. Those conditions match the actual layout need, survive resizing and rotation without breaking, and are easier to test. Use orientation queries only where the physical posture of the device is genuinely part of the requirement — media players, fixed-orientation kiosks, and games — and even then prefer explicit aspect-ratio checks or a platform-level orientation lock over a global landscape stylesheet.