Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

CSS Media Queries for Portrait Orientation

Use CSS’s portrait orientation media query to style a viewport whose height is at least its width, and learn how keyboards, iframes, and breakpoints affect it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use @media (orientation: portrait) to apply CSS when the relevant viewport is at least as tall as it is wide. It tests the viewport’s shape—not whether a phone or tablet is physically held upright—so a square viewport also matches portrait.

Write a portrait orientation media query

Put the styles that should apply in an @media rule with the portrait value:

/* Base layout applies unless a matching query overrides it. */
.cards {
  display: flex;
  flex-direction: row;
  gap: 1rem;
}

@media (orientation: portrait) {
  .cards {
    flex-direction: column;
  }
}

Here, the cards stack when the viewport is portrait or square; otherwise, they remain in a row. The selector and property should reflect the layout change you actually need. Orientation does not identify a particular device class or screen size. See the MDN orientation reference for the feature and example.

You can include a media type when useful: @media screen and (orientation: portrait) { ... }. The condition itself is (orientation: portrait). The corresponding value for a wide viewport is landscape.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

What portrait means to CSS

CSS evaluates orientation using the geometry of the viewport (or the page box in paged media). Portrait means its height is greater than or equal to its width; landscape means its width is greater than its height. Therefore, a square viewport matches portrait. This is the definition in the CSS Media Queries Level 5 draft.

The query does not read a device-orientation sensor. A browser window or iframe may have a shape that differs from the device display, and CSS uses the viewport relevant to the page or frame being styled.

Choose orientation, width, height, or aspect ratio

Use the condition that describes the constraint your layout responds to:

Layout need Condition Why it fits
Switch behavior between tall-or-square and wide viewports (orientation: portrait) or (orientation: landscape) Tests the portrait/landscape geometry category.
Change layout at a horizontal-space breakpoint (min-width: ...) or (max-width: ...) Tests the available width directly.
Respond to limited vertical space (min-height: ...) or (max-height: ...) Tests the available height directly.
Respond to a particular width-to-height proportion (min-aspect-ratio: ...) or (max-aspect-ratio: ...) Tests the viewport’s proportion rather than just its orientation category; see MDN’s aspect-ratio reference.

Do not use orientation as a synonym for “mobile.” A narrow desktop window can be portrait, while a phone or tablet can be landscape. If the real issue is whether content fits horizontally, use a width breakpoint; if it is the viewport’s proportions, use aspect ratio.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Why portrait styles may change when the keyboard opens

On some devices, opening the soft keyboard changes the available viewport dimensions enough to make it wider than tall. The browser can then match landscape rules even while the device remains physically upright. An iframe also evaluates orientation against its own viewport, not necessarily the surrounding page’s.

When a layout behaves unexpectedly, inspect the viewport whose CSS is being evaluated and test with the keyboard open. Check whether the viewport’s width has exceeded its height before changing the query.

Test the layout in a browser

  1. Identify the constraint. Decide whether the design depends on tall-versus-wide geometry, a specific width, a height limit, or a proportion.
  2. Apply the matching condition. Add an orientation, width, height, or aspect-ratio media query around only the styles that need to change.
  3. Resize and rotate. Check the layout in portrait and landscape shapes, including a square viewport if that boundary matters to the design.
  4. Check the actual viewport. For embedded content, test inside the iframe. On touch devices, test with the soft keyboard open if users can trigger it.

Orientation and aspect-ratio features are broadly available, but the references cited here do not provide a version-by-version compatibility matrix. Consult current compatibility data for a specific browser support requirement rather than assuming a particular minimum version.

Troubleshoot a portrait query that does not behave as expected

  • The rule matches on a square viewport: that is expected; square counts as portrait because the height is equal to the width.
  • The rule changes while the device stays upright: CSS follows viewport geometry, not physical rotation. A soft keyboard can change that geometry.
  • The main page and embedded content disagree: the iframe has its own viewport, which determines the query result for styles inside it.
  • The rule applies on a desktop window: orientation describes shape, not device type. A narrow window can satisfy portrait.
  • The design breaks at a particular width: use a width condition instead of orientation if the actual requirement is a breakpoint.
  • The design depends on a precise proportion: use an aspect-ratio condition when a simple portrait/landscape category is too broad.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot of the result without setting up a browser capture workflow, ScreenshotNeo is a website screenshot API and MCP server. A single request can return an image or PDF; its documentation lists the request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Before capture, it accepts consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.