• Write for us
  • Advertising

Web Development, Networking, Security, SEO

CSS3 Media Query to target only Internet Explorer (from IE6 to IE11+), Firefox, Chrome, Safari and/or Edge A set of useful CSS3 media queries to target only specific versions of the various browsers: Internet Explorer, Mozilla Firefox, Google Chrome, Apple Safari and Microsoft Edge

CSS3 Media Query to target only Internet Explorer (from IE6 to IE11+), Firefox, Chrome, Safari and/or Edge

Table of Contents

IE 6, 7 and 8

Ie 8 standards mode only, ie 8,9 and 10, ie 9 and above, ie 9 and 10, ie 10 and above, ie 11 (and above..), microsoft edge, any version (gecko), quantum only (stylo), legacy (pre-stylo), chrome & safari (any version),  safari (7.1+), safari (from 6.1 to 10.0), safari (10.1+).

If you're a HTML developer you most likely know that there are times when you need to selectively apply some styles to a specific browser, or to a specific version/build of a browser. When such scenarios occur, there are a number of CSS and/or JS based techniques to achieve that result.

Here's a collection of media queries that will allow you to do that in pure CSS3 code, without a single line of JavaScript code: most of them come from the  browserhacks.com web site, which is an excellent resource of browser-specific CSS and JavaScript hacks for these kind of tasks.

Internet Explorer

For further info or additional media queries, visit the awesome browserhacks.com website!

Print Friendly, PDF & Email

Related Posts

TS2564 (TS) Property has no initializer TypeScript error in Visual Studio 2017 - How to fix

How to become a Web Developer: a detailed plan for learning JavaScript A list of the main study topics that await a novice JavaScript developer in his/her learning path to become a great web developer

May 19, 2020 May 19, 2020

Tabulazer - Chrome Extension to Filter and Sort HTML Tables

Tabulazer - Chrome Extension to Filter and Sort HTML Tables A free Google Chrome Extension that can be used to filter, sort and enlarge HTML tables from any web page

October 2, 2019

7 typical reasons why Bootstrap is ideal for responsive Web Design

7 typical reasons why Bootstrap is ideal for responsive Web Design A list of some great features that still makes Bootstrap the world’s most popular front-end component library

July 25, 2019 July 25, 2019

safari specific media query

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

6 Comments on “ CSS3 Media Query to target only Internet Explorer (from IE6 to IE11+), Firefox, Chrome, Safari and/or Edge A set of useful CSS3 media queries to target only specific versions of the various browsers: Internet Explorer, Mozilla Firefox, Google Chrome, Apple Safari and Microsoft Edge ”

Using a media query like this, @media screen and (-webkit-min-device-pixel-ratio:0) and (min-resolution:.001dpcm) {, to only target Chrome previously worked but now Firefox is picking up those styles in that media query. Any ideas for another workaround for just Chrome? Thanks!

Try one of these:

The css for ‘Safari (from 6.1 to 10.0)’ affects ALL browsers on iPad: Chrome, Safari, Opera. Not only Safari.

_:lang(x)::-ms-backdrop, .selector { color: blue; } /* IE11 */ _:-ms-lang(x)::backdrop, .selector { color: blue; } /* Edge */ _:lang(x)::-internal-media-controls-overlay-cast-button, .selector { color: blue; } /* Chrome */ _:lang(x)::x-, .selector { color: blue; } /* Safari */ _:-moz-any(x), .selector { color: blue; } /* Firefox */

not from me

sadly that edge things no longer works.. kind of tough to find an edge only query..

How to add a media query for a specific browser with specific width? for e.g. Safari browser version 10 and above with width: 1440px

Leave a Reply Cancel reply

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

 Aggiungi e-mail alla newsletter

Notify me of follow-up comments by email.

Notify me of new posts by email.

This site uses Akismet to reduce spam. Learn how your comment data is processed .

WebKit Features in Safari 16.1

Oct 24, 2022

by Jen Simmons

Web Push for macOS Ventura

Animated avif, new viewport sizes on ipados, hover on ipados with apple pencil, scroll to text fragment, screen capture improvements, fixes and polish.

Today, Safari 16 arrives for macOS Ventura and iPadOS 16. Numbered Safari 16.1, this release is also available for iOS 16, macOS Monterey, and macOS Big Sur.

To update to Safari 16.1 on macOS Monterey or macOS Big Sur, go to System Preferences → Software Update → More info. To update your Mac to macOS Ventura , go to System Settings → Software Update. To update to Safari 16.1 on iPad and iPhone, update iPadOS 16 and iOS 16 in Settings → General → Software Update.

Features that shipped in September’s Safari 16.0 include Container Queries, Subgrid, Web Inspector Extensions, Flexbox Inspector, Offset Path, Overscroll Behavior, Shared Workers, Shadow Realms, resolution media query, :has(:target) , text-align-last , animation-composition , discrete animation, accessibility improvements for display: contents , improved VoiceOver performance, additional Apple Pay support, new Web Extension APIs, Manifest version 3 support, and much more. Safari 16.1 brings all of these features to iPadOS 16 and macOS Ventura.

Now let’s look at the new features and fixes arriving with Safari 16.1.

a push notification on macOS

Safari 16.1 for macOS Ventura brings support for Web Push to Safari. Websites and web apps can now remotely send notifications using the same standards supported in other browsers — Push API and Notifications API , along with Service Workers — and deliver those notifications even when Safari isn’t running.

In Safari, users of your website or web app opt into notifications by first indicating interest through a user gesture — such as clicking a button. Then they’ll be prompted to give permission for your site or app to send notifications. Users can view and manage notifications in Notifications Center. And they can customize styles and turn notifications off per website in Notifications Settings.

If you’ve already implemented Web Push for your web app or website using industry best practices, it will automatically work in Safari. You do not need to be an Apple Developer Program member. However, if you’ve excluded Safari through browser detection, you’ll need to switch to feature detection to get it working. Web Push in Safari uses the same Apple Push Notification service that powers native push on all Apple devices. If you tightly manage push endpoints on your server, be sure to allow URLs from any subdomain of push.apple.com.

To learn more, watch the WWDC session Meet Web Push for Safari (15 min video), or read the article Meet Web Push on webkit.org.

Safari 16.0 brought support for AVIF still images to iOS 16. Safari 16.1 adds support for AVIF animated image sequences. Now both still and moving images saved in the AVIF format are supported on iOS 16, iPadOS 16, and macOS Ventura.

In September, iOS 16 introduced passkeys. Now with Safari 16.1, passkeys are supported everywhere Safari 16 is supported — including iPadOS 16, macOS Monterey, macOS Big Sur, and macOS Ventura, as well as iOS 16. Passkeys provide users with an incredibly easy way to log in, while delivering a profound increase in security .

The technology that makes passkeys possible is defined in open standards from the FIDO Alliance and the W3C, including the WebAuthn standard, which already has widespread support in browsers . Passkeys are an industry-wide effort, and “passkeys” is a common noun, to be used by anyone. You can offer passkeys alongside your existing authentication options. First, teach your backend to store public keys and issue authentication challenges. Then, on your website or web app, offer passkeys to users by adopting the APIs for creating new passkeys and allowing users to sign in with their passkey. If your website or web app already supports using a platform authenticator with WebAuthn, there are a few things to note as you add support for passkeys. Make sure you aren’t limiting signing in to the device that saved the passkey; that is, don’t use a cookie to “remember” that a user set up a key on a particular device. Also, make sure the username fields in your existing sign-in forms are compatible with AutoFill by adopting “conditional mediation”. Finally, start to refer to passkeys, and treat them as a primary way to sign in.

To learn more, watch the WWDC22 session, Meet Passkeys (27 min video) or read Supporting passkeys .

Three Safari browser windows, layered over one another, floating in space. One tall and very narrow. One medium and square. One bigger and wide.

iPadOS 16 introduces an entirely new multitasking experience with Stage Manager. This means browser windows on iPadOS can be resized to many different viewport sizes and aspect ratios. Responsive web design techniques, including the use of CSS media queries and container queries, are key. There’s never been a single “tablet size” for layout, and now that’s more true than ever.

The new iPad Pro supports hover with Apple Pencil. In web browsers, users see hover states for links, animations, and more. Hover on iPadOS is yet another example of how structuring code using feature detection , instead of device or UA detection , helps future-proof websites and web apps.

Safari 16.1 adds support for Scroll to Text Fragment , making it possible to include a text directive for finding a text fragment as part of a URL. When a user navigates to a URL that includes such a directive, the browser scrolls the text fragment into view and marks it with a persistent highlight.

screenshot of dialog message asking Allow webkit.org to share your screen?

On macOS Ventura, Safari 16.1 adds support for capturing a specific Safari window with getDisplayMedia() . Calling getDisplayMedia in response to a user action will show the user a prompt asking for permission to allow the sharing of their screen or a specific window of an application, including Safari windows. The MediaStream provided by getDisplayMedia contains a video stream of the screen or window that can be recorded, or used as part of a WebRTC session.

Safari 16.1 adds support for web-to-App Store advertising with SKAdNetwork. It also adds support for WebDriver Wheel input source and actions. Safari Web Inspector adds support for the color picker to pick a color from any pixel on the screen.

Safari 16.1 also contains bug fixes and feature polish. Many of these fixes improve the Interop 2022 score for Safari. The test pass rate for Safari 16.1 is 93.3%. That’s calculated from 84.3 points of a possible 90. The remaining 10 points are joint “investigation projects”.

Accessibility

  • Fixed display:contents buttons failing to expose their accessible name.
  • Fixed dynamic viewport height units ( dvh ) not matching the actual viewport height.
  • Fixed scroll-snap properties set on <body> to stop propagating to the viewport.
  • Fixed logical viewport units to properly resolve for font-size .
  • Fixed containing blocks with a non-visible overflow incorrectly clipping position: fixed descendants.
  • Fixed table user-agent styles to use box-sizing: border-box .
  • Fixed <select> elements with contain: size .
  • Fixed handling layout and paint containment.
  • Fixed handling font-variant: normal and font-variant: none shorthands to reset font-variant-numeric and font-variant-alternates .
  • Fixed small caps handling to prevent synthesizing if any character in the font supports small caps.
  • Fixed the ignored CSS color property on <select> elements.
  • Fixed hiding icons on <input type="search"> when appearance: textfield is set.
  • Fixed applying the readonly attribute to the correct <input> types and <textarea> element.
  • Fixed the content width for <input type="search"> to not include decorations.
  • Fixed input type state changes to correctly handle missing or empty string value attributes.
  • Fixed form.submit() to submit a single form to multiple frames concurrently.
  • Fixed cloning a <textarea> to not set the initial selection at the end of the text content.
  • Fixed not firing a select event when setting a selection range results in no change to the selection.
  • Fixed some AVIF images not rendering because of their container format.
  • Fixed preventing background propagation on <html> with any containment.
  • Fixed COOP same-origin breaking forms after a back navigation.
  • Fixed script-src-elem CSP in Workers.
  • Fixed focus behavior for shadow DOM and the <dialog> element to align with specifications.

We love hearing from you. Send a tweet to @webkit , @jensimmons , or @jonathandavis to share your thoughts on Safari 16.1. If you run into any issues, we welcome your feedback on Safari UI, or your WebKit bug report about web technology or Web Inspector. Filing issues really does make a difference.

Download the latest Safari Technology Preview to stay at the forefront of the web platform and to use the latest Web Inspector features. You can also use the WebKit Feature Status page to watch for new information about the web features that interest you the most.

To learn more about what’s in Safari 16.1 for web developers, read the Safari 16.1 release notes .

Change CSS rules only in Safari

FabioRosado Saturday 5th, May 2020 2 mins to read 0 Like 0 Comment

How to apply css rules to safari only

The solution.

While working on Thumbs Up News , I've noticed a strange UI bug that happened only on Safari, when the screen was smaller than 900px height-wise. All the other browsers where okay, but the subscribe button was broken. The border was pushed up outside the area of the button and was now between the two elements of the menu. This only happened when a user clicked the categories button and the sub-menu expanded. I'm assuming that this happens because Apple wants space for its bottom menu?

The mobile menu is set on a fixed position. It seems that Safari will change either the padding, the margin or just some border rules when that fixed element doesn't have enough space vertically to show some space under the last element. My first thought was to use the -webkit rule to increase the padding on the button. Using that rule fixed the issue on Safari but broke on Chrome and this is when my search on how to apply CSS rules to a specific browser started.

After searching for a while, I've come across this article written by Ryan - CSS3 Media Query to target only Internet Explorer (from IE6 to IE11+), Firefox, Chrome, Safari and/or Edge , if you scroll down you come to this little hack that works on Safari 10.1+.

I am using Sass on Thumbs Up News and that means I can't have an empty @media rule. But this was a great starting point for coming up with a solution. I've removed the empty media query to see if the rule would work on Safari and not on any other browser. Surprise, surprise, it worked! Now I decided to play around with the media query rule a bit more, to see what works and what doesn't work.

The Safari only rule hack has two parts. You need to use a unit that is not supported by Safari - dpcm , dpi , dppx and you need to set that media query to not all . The not all rule is important so chrome doesn't pick it up.

After testing different things and playing around with the media query, I've come to the final solution. I've also added a rule to trigger the CSS only when the screen is smaller than 900px high, because we don't want the menu to be broken on a larger screen.

That's all there is to get a media query work on Safari only. I'm still wondering why this trick works and would love to know why, so if you know the answer please let me know!

Webmentions

You might also like these.

A lot of sites make the first letter of a paragraph spread to multiple lines, let me share with you how you can do it.

Make the first letter spread multiple lines

Make the first letter spread multiple lines

Nx makes it easy to work with monorepost, this article will show you how you can use Nx for your projects and talks about some basic commands that will help you.

Getting started with Nx

Getting started with Nx

How to set up an UI element persistent in Gatsby to allow users from Landing in Tech to listen to the latest episode, when navigating the site.

How to make a UI element persistent in Gatsby

How to make a UI element persistent in Gatsby

How to create a function to filter articles by tag. On this post I am using the javascript filter method to filter all articles.

How to filter all MDX articles by tags

How to filter all MDX articles by tags

Kilian Valkhof

Building tools that make developers awesome., i want my own media queries in browsers.

We’re on the verge of a whole lot of new CSS media queries becoming available. But if you’re a developer that wants to get a head start and try them out, you’re out of luck. Browsers are prototyping them one by one before making them available and we as developers have to wait.

Prefers-reduced-data is an upcoming media query that lets you know a user would like to use as little data as possible. Maybe their connection is slow or unstable or they’re on a capped data plan. (Read more about it in the complete guide to css media queries )

I’m excited about it, because it can really make a difference to your users. It remind me of the time YouTube ruthlessly improved their load time and then found out their average load time had gone up , the opposite of what they were trying to achieve. Turns out, due to the improvements YouTube was now fast enough to use in new places that had much slower connections. Prefers-reduced-data could do that for your site.

Since Chrome 86+ web developers can now preview and test with this feature. Turning prefers-reduced-data on is simple:

  • Go to chrome://flags.
  • Search for “experimental web platform features” and turn that on.
  • Go to your site and open dev tools.
  • Then click the three dots in the top right.
  • Go to “more tools”.
  • Then pick “rendering”.
  • now scroll down and you can use the dropdown to emulate the prefers-reduced-data media feature.

…except that’s not quite such a straightforward set of steps.

Not only did we as developers have to wait for Chromium to implement it because we could do any useful testing, it’s also pretty hidden.

Testing new media queries earlier

Wouldn’t it be great if testing such a potentially important media query was easier? What if browsers could just “pretend” to support new media features so us developers can already implement them in our stylesheets and test them, even if browsers did nothing to implement them themselves?

Quick aside: Don’t custom media queries solve this? Not really: they let you create a named media query that maps to one or more existing media queries, not define entirely arbitrary ones.

I want to go one step further even. I would love to be able to tell Chrome and other browsers to support any media query I define that I can then set to different values in the developer tools and test against.

A while ago I filed a Chromium bug to do exactly that: Feature: emulate arbitrary media features

If the Chrome dev tools supported arbitrary media features, we as developers could:

  • Play around with upcoming media queries (like prefers-contrast ) before they land to see how we could adapt our CSS to it ahead of actual support.
  • Try out our CSS for media queries only supported in other browsers.
  • Build our own domain-specific media queries for development.

The benefit of getting ahead of browser support for media queries your stylesheets is self-explanatory, and checking e.g. Safari-specific media queries in another browser is just convenient, but it’s the last category that is really exciting to me.

It has the potential to simplify a lot of development.

You might include debug CSS and then comment that in or out in your stylesheet, or toggle it with a class on the html element, like Pesticide , styles that show the currently active breakpoint or a11y.css .

Imagine instead of dealing with that in your own CSS and JS, with all the potential for mistakes ending up in production, your debug CSS was just wrapped in something like this:

(The !-- notation is just an idea to mirror the -- notation for custom properties and <!-- notation for HTML comments)

It’s not a “valid” or existing media query, so browser in normal mode would just evaluate it to “ @media not all {} ” and any CSS in it will be ignored. (ideally you’d also remove it from your CSS before it goes to production).

In the dev tools you would then add the !--debug-styles media feature and set its value to “on” and that would activate your CSS. You could have just one custom media query, or a whole set to test different parts of your CSS. Up to you.

Suddenly without effort you could have all sorts of debug CSS active during development (making sure you purge that for production) and use the dev tools to toggle them on, off, or any arbitrary value.

Interesting idea?

If that sounds interesting, please consider starring the chromium bug or Web we want request to indicate interest, and I’d love to hear your thoughts via Twitter .

Polypane browser for responsive web development and design

Related Posts

Media queries are what make modern responsive design possible. With them you can set different styling based on things like a users screen size, device capabilities or user preferences. But how do they work, which ones are there and which ones should you use?

CSS Media Queries Level 5 is coming and though it’s still heavily in progress, there is a particular new option that feels like a mistake in the making to me: prefers-contrast: forced. I’ll explain why I feel that way in this article.

Last December I wrote an article in Dutch for the Fronteers blog on a fun bit of CSS I wrote that use 3D transforms to create a cool looking effect: Porky Pig coming out of those red rings announcing the end of a Looney Tunes cartoon. At the time, I was creating a resource of […]

bugfix release that improves Portal availability and fixes a blank window issue.

Bugfix release that improves handling of localhost addressess.

Bugfix release that improves handling of address bar autocompletion.

The complete guide to CSS media queries

From the polypane blog.

Table of contents

What are media queries?

The and operator, the or operator: , (a comma), the not operator, media query in html, using media queries, width and height, aspect ratio, implementing a dark mode, implementing reduced motion, prefers-contrast, color-gamut, display-mode, resolution/-webkit-device-pixel-ratio, inverted colors (safari only), dynamic-range, multiple pointing devices, prefers-reduced-data (no support) available for testing in polypane, prefers-reduced-transparency (chromium 118, supported behind a flag in firefox), overwriting forced colors, -ms-high-contrast (supported in old edge), light-level (no support), scripting (supported in firefox 113, safari 17 and chromium 120), nav-controls (no support), environment-blending (no support), screen-spanning (supported in chromium browsers), range: replacing min-* and max-*, not() function, custom media queries.

  • Device-* media queries

prefers-color-scheme lost a value

Using media queries in javascript, test your media queries with polypane, the browser for developers and designers.

If you want to be kept up to date with new articles, CSS resources and tools, join our newsletter.

Media queries are what make modern responsive design possible. With them you can set different styling based on things like a users screen size, device capabilities or user preferences. But how do they work, which ones are there and which ones should you use? Here's the complete guide to media queries.

What this guide will go through:

How a media query is structured

Media types, using media query features.

  • Upcoming media queries

New notations in Media query levels 4 and 5

Deprecated media queries.

  • Using Media Queries in JavaScript

What is a media query? A media query is a specific feature of CSS that lets you conditionally apply styling based on a media type, a media feature or both. You use them primarily to check the screen dimensions and apply CSS based on that, but media queries can do many other powerful things.

Here's the general structure of a media query:

It begins with the @media keyword, also called an "at-rule", optionally followed by a media type and zero or more media features .

A real example of a media query is:

In English, what this says is this: "if the site is being shown on a screen and that screen's width is at least 400px wide, apply this CSS".

Both the media type and the media feature are optional, so this is a valid media rule:

And this is a valid media query too:

If you leave out the media type, it will be seen as the media type all , which is usually fine.

Logical operators

Next to media type and media features, we also have a few "logical operators" that go inbetween those parts: and , or and not . Here's how those work:

You can use the "and" operator not just between a type and a feature, but you can also use it to "chain" multiple media features using and , like so:

Which tells a browser to apply this CSS if the browser width is between 400 and 800 pixels.

You can use a comma to do "or", like so:

which applies to screen or print. Each comma separated line is its own media query and as soon as one of them evaluates to true, the CSS in the media query is applied. In the future you'll also be able to use or instead of a comma .

Lastly, there is not , which can be used to negate an entire media query. So the following query will be applied everywhere except print:

If you use the not operator you must set a media type (like screen or print) as well. If you don't, the media type will be all , and then your media query will read "not all" so it won't get applied anywhere.

not inverts the entire media query. Scroll down to not() notation for an upcoming feature that will allow you to negate just a part of a media query.

There's also the only logical operator, but in modern browsers you don't need to use this, so we'll pretend it doesn't exist.

You can nest media queries in other media queries and that will work fine! So instead of

you can also write

In this example it might not be so useful, but you could wrap your entire CSS in an @media screen {} and do your responsive design with nested media queries, and then have a fully custom print stylesheet. With this, that'll look a little cleaner.

You can optionally append one or more comma-separated media queries to the import statement to conditionally import the file, for example like so:

If a media query does not match, the CSS won't be applied, but the file will still be downloaded.

You can also use a media query in your HTML, for example in a <style> or <link> tag, like so:

It's worth noting that any linked files will still be downloaded by your browser even if they doesn't apply.

You can also use media queries to control which responsive image to load using the img element with a sizes attribute, or a picture element with different source elements that each have a media attribute, but since that's a large topic and does not concern CSS, we'll leave that for another guide.

The media type is used to describe the type of device that a browser is running on. There used to be loads, but the level 4 specification deprecated a whole lot that were never implemented anyway, leaving us with 3 we should care about:

As mentioned earlier, if you don't specify a media type, it will default to "all", which means the css will apply to all devices.

Probably what you're reading this article on now!

For when you print a page, or any "paged" media (Like a book! Did you know people use HTML and CSS to mark up books?)

safari specific media query

Did you know you can easily switch between screen and print stylesheets in Polypane with our emulation features?

So just for completeness, here's all the other ones that you never got to use, and probably never will:

  • aural (which was replaced by speech ),
  • speech (...also deprecated. Originally for use with speech synthesizers, like screen readers. Never implemented in browsers.)
  • tty (for the terminal),
  • tv (... like a screen, but different...somehow?),
  • projection (projectors),
  • handheld (for phones, they were actually used for a while before media expressions were a thing),
  • braille (for braille devices) and
  • embossed (like a combination of print and braille, so for printed braille).

When using media queries it's good to give yourself a few rules, so you don't randomly add media queries and end up with CSS that behaves unpredictably and is hard to maintain.

When starting fresh, I recommend to write CSS from narrow (mobile) to wide (desktop) and then only using min-width for your styling. That way you're always designing "up" and your CSS remains easy to reason about: All the CSS you write will be additive compared to the base styling. Your original CSS might place things in a column:

and when you get wide enough to show two columns, you switch to horizontal:

Because the main element already has display: flex; , all we needed to do at the wider breakpoint is change the flex-direction . We prevent code duplication and everything is more readable and faster to download.

We can extend this reasoning to all the media features described below. Write your CSS for the starting point: the most well-supported, the smallest or the most accessible version. Then progressively add more styling using media queries.

For more in-depth tips on how to develop a responsive website, read our article Responsive design ground rules .

Media query feature make up the main part of a media query and have the most influence on what you're designing. Media feature do a lot . They let you check for device and browser capabilities, settings and user preferences beyond just the type of device.

By far the most used media features are related to browser dimensions. Here are they:

You can check for exact width , min-width and max-width , and exact height , min-height and max-height .

width and height you'll probably never want to use, they only apply at that exact width.

More useful are the min-* and max-* values, which let you write CSS for screens starting at a certain size and larger (using min-* ), or up to a certain size (using max-* ).

All the width and height media features support the regular CSS units like pixels and ems. It's recommended to use the em unit for media queries, so it scales nicely when people zoom in their browser . This won't happen with pixels, and rem is the same size as an em when it's used in media queries. rem also has some bugs in Safari. So, em 's are best.

If you think sizing in em s is hard because you don't know how large an em is: media queries are handled at the top level, so 1 em is always 16 pixels or what the browser set as the default font size (and so are rems).

Did you know Polypane automatically detects the width and height media queries in a site and creates panes for them? That way, you're always building sites to your own specifications. It also supports sizing panes in ems so you don't even have to calculate between pixels and ems!

You can also test for the relation between width and height, with the aspect-ratio and orientation media features.

The aspect-ratio media feature takes a fraction, and also has the more useful min-aspect-ratio and max-aspect-ratio media features. It will lets you check if a browser has a certain ratio between width and height. The way to think about it is: the first number represents the width, the second number represents the height. This means an aspect ratio of 2/1 is twice as wide as it is high.

You can test for (only) square screens:

Or check for screens that are 16 by 9:

Like width and height, you'd usually use the min-* and max-* variants. With a certain aspect ratio you can decide to show images in a portrait or landscape mode, for example.

With min-aspect-ratio , you can check for screens that are wider than they are high:

Conversely, by using to max-aspect-ratio: 1/1 , you switch that around to only screens that are higher than they are wide.

Instead of doing that though, you can also just use orientation: landscape and orientation: portrait , which mean the same thing and are a little clearer.

Prefers-color-scheme

With prefers-color-scheme you can check if a user prefers to see a dark mode or light mode version of your website.

Some users might prefer dark mode because it's easier on their eyes, because their environment is dark or because they're sensitive to bright lights. Conversely, users might prefer your light mode for the usually increased contrast or because they visit your site in a bright space.

Here's how to test for both:

Between, these, light is considered to be the default. So much so, that a third option no-preference was recently removed from the specifications due to lack of implementations.

safari specific media query

Did you know Polypane's emulation mode makes it really easy to test both a dark and light theme side-by-side.

If you already have a website and want to add dark mode, the neatest way to go about it is to redesign each part. This will give you the most control and highest quality implementation.

For many sites, it might be hard to go through all parts of a site, or there's no time or budget available. For those sites, there's a thing I like to call "cheap dark mode", and it looks like this:

Here's how it works: First we set a dark background on the :root , which is basically the html element. This doesn't have to be #111 (very dark gray), it can also be pure black (#000) or you can add a little color to it. That all depends on your brand and design, so pick one that works for you.

The next line is where the magic happens. With filter we can invert all the colors. This will make light dark and dark light. It won't affect the background which is why we defined that ourselves.

Invert also has another effect though, it also inverts colors. So blue will become orange, green becomes pink and so on. That's not great, because it means you just lost your brand colors. Fear not though, we can get them back by rotating the hue back to the original colors with hue-rotate(180deg) , undoing the invert specifically for the hue of your colors.

At this point, all images and videos on your site look super weird, so what we need to do there is double-apply the invert and hue-rotate, turning both back to their original colors. Now you have a site in dark mode, where all images and videos are shown as they are. Not bad for just a few lines of CSS!

Prefers-reduced-motion

With prefers-reduced-motion , users can indicate they want to see less stuff happening on screen. The reason they want to do this can be things like motion sickness, vestibular disorders or they just plainly don't want to wait for your nice animations to finish.

If a users has prefers-reduced-motion turned on it doesn't mean they want no motion, but you have to be mindful: use motion only where it helps understanding and if you do, keep the motion small (so fade instead of swoosh ). Otherwise just turn them off. And for video's, make sure you don't auto-play them .

If you're starting a new project and want to incorporate support for reduced motion it's a good idea to consider motion an enhancement: have no or little motion as the default, and only when refers-reduced-motion: no-preference is set, add additional motion to your website. That way, the default experience is the more accessible one.

For an existing site, this might be a lot of work, so we also have a cheap reduced motion script:

This will turn off all animation for all elements so it's as relatively blunt method, but it's perfect to retroactively add to a site to make it more accessible. The animation is set to 1ms so the animationend and transitionend events are still fired because your javascript might depend on them, but with the negative delay you won't notice the difference.

Did you know Polypane makes it really easy to test your prefers-reduced-motion implementation side-by-side with a regular pane.

Prefers contrast indicates whether a users prefers more or less contrast in their interface. For example visual impairments can make it difficult to make out details or subtle differences in color so people that have that will prefer higher contrast. On the other hand, other people might be sensitive to harsh high contrast and prefer colors to be closer to each other.

prefers-contrast: custom is an odd one out. If you dont prefer more , less or the same ( no-preference ) contrast, why does this exist? The custom value will match when forced-colors is active but the user doesn't have a high or low constrast theme selected, but something in the middle. This way, @media (prefers-contrast) without a value will still match and that will let you re-use the media query to reduce visual complexity.

The "increase contrast" option in the macOS accessibility menu will trigger prefers-contrast: more :

The macOS settings with increase contrast turned on

When you turn it on, your entire operating system also switches to an increased contrast mode which you can use for inspiration on your site. As you can see from the screenshot, macOS doesn't turn everything full black on full white (though it does bump up the text contrast), but instead it increases the contrast between sections, by adding clear borders instead of soft shadows and suble background tints.

On Windows, prefers-contrast is turned on when you turn on forced-colors and will match more , less or custom depending on the contrast ratio between the background and default text color.

Did you know Polypane makes it really easy to test your prefers-contrast ands forced-colors implementation side-by-side with regular panes.

Colors on the web so far have been limited to just the sRGB color gamut, but modern screens are able to display much more colors, like the p3 color space. With the color-gamut you can test if a device has such a wider color space.

There are three potential options, and if it supports the larger color space, it automatically includes support for the smaller color space.

  • srgb This is the one we all know :)
  • p3 This is what for example modern iPhones use, often called "wide gamut"
  • rec2020 , this is the largest color space available right now, but you basically won't find this in the wild.

If a user has a display with a wider gamut, you can use images in that color space and they'll be more vibrant than ones in sRGB.

Not supported yet, but coming soon are new CSS notations you can use to describe colors in these wider color space (since this is not possible with rgb , hsl or hex, which are limited to sRGB).

For these new colors, there are three new css functions: lab() , lch() and color() . For now, only Safari supports the color() function, and the other two are supported nowhere.

Lab and lch allow you to describe more precise colors than rgb and hsl, but with color() you can explicitly opt-in to a color gamut, like so:

The display-p3 is the only value supported for now, and the three numbers are floating point numbers for the R, G and B channel.

If you're designing a game or video player, you might have more than just the game/video on the page but when someone switches to fullscreen you only want to show the game/video. This media query lets you do that. display-mode is supported by all modern evergreen browsers, and will let you test for how your site is shown with four possible options:

  • browser This is the default mode, where your page is shown in a regular browser window.
  • fullscreen Your page is displayed full screen and there is no browser chrome visible. If there is no fullscreen media query defined, your browser will instead apply styles defined in a standalone media query.
  • standalone The page is not shown fullscreen, but also doesn't have all of the regular browser chrome, Instead it looks like a standalone (desktop) application. If there is no standalone media query defined, your browser will instead apply styles defined in a minimal-ui media query.
  • minimal-ui Your page is shown in its own window, but the browser will still show some chrome for controlling navigation (like popup windows). If there is no minimal-ui media query defined, your browser will instead apply styles defined in a browser media query.

As you can see, most of these values fall back to the next one, so if you define a minimal-ui style, that will also be applied to standalone and fullscreen .

With the resolution media query you can test for a displays pixel density. There is resolution , which tests for a single specific pixel density and min-resolution and max-resolution which give a lower and upper bound.

You can use this to serve retina background images to displays that support it, for example.

Resolution takes a number with either a dpi (dots per inch), dpcm (dots per centimeter) or dppx (dots per pixel). In CSS, a pixel is always 96dpi , so 1dppx is a regular screen resolution, and 2dppx is 'retina'.

Instead of dppx you can also just use x , so your CSS could look like this:

Older versions of Safari (before TP Release 138) don't support the resolution media query. They have a similar feature called -webkit-device-pixel-ratio (as well as -webkit-min-device-pixel-ratio and -webkit-max-device-pixel-ratio ), which accepts a number without a unit. The implied unit is the same as dppx though, so the following CSS has the same effect as the resolution sample above:

To improve support, all other modern browser also support the -webkit-device-pixel-ratio notation so between resolution and -webkit-device-pixel-ratio , you can safely use the latter for the widest support. Consider switching to resolution though, unless you also need to support older versions of Safari.

Overflow can test how a device handles content that's larger than fits. It exists of two properties, overflow-block , for the block direction (usually top to bottom) and overflow-inline for the inline direction (usually left to right).

For overflow-block there are 4 potential values to check against:

  • none , meaning that anything that overflows is simply not displayed
  • scroll , you can scroll to content that overflows
  • optional-paged , you can scroll but page breaks can be manually triggered
  • paged , content that overflows is shown on a next page.

And overflow-inline only has two values:

update is used to detect how often the media type can update. Possible values are:

  • none , meaning it can't update, like printed paper.
  • slow , where updating is slow like on e-book readers or low power devices.
  • fast where updating is not constraint by device capabilities, like regular screens.

This media query indicates that the operating system has inverted all colors. The operating system in this instance is MacOs, the only operating system that supports this (and conversely, only Safari supports this media query). It's either off or on:

You might think that you'd use this to double-invert your images and videos like we did with our cheap dark mode , but Safari already does this for you. You can however, still hue shift your entire site to make sure your brand colors are followed.

Some displays can display "HDR", or "high dynamic range", characterized by large contrast, brightness and color depth. The specification gives two options: high and standard . If it's high, this means that you can use display-p3 colors (currently only supported in Safari) to provide more vibrant colors for your visitors. To test for support for specific color spaces, you can use the color-gamut media feature

Interaction: pointer and hover

We have many more different input/pointing devices now compared to when the web got started. Mouse pointers still exist, but we also have touch, external controllers like Wii remotes and even things like AR hand detection.

Some things that are easy to do with a mouse are harder or impossible to do with touch devices, like hitting small targets or even hovering. With the interaction media features you can adapt to these devices in clever ways.

The way I would go about this is consider a touch device as the most minimal implementation. It won't have hover effects, and the precision of your input device is coarse (It's the size of your thumb).

For this group, you can't have things popping up on hover so they need to be visible or behind an explicit toggle, and your tap targets will need to be larger.

But those devices could also have support for a stylus, still not allowing hover, but making it easier to point to specific parts on the screen. While it's a good idea to have large enough clickable targets even if pointer: fine, you can for example place them closer and make more efficient use of the space.

Then as you start to get hover capabilities, you can add those with:

Devices that allow for hovering but have a coarse pointer are things like Wii controllers and Kinect. They let you point at things but without great precision. You'll want large enough targets and you can add hover effects as an indication of where they're pointing.

Lastly, we end at what many will think of as "normal", but is actually the most well-featured situation: a device with a mouse/trackpad.

These devices can hover over elements and precisely target them. Users of these devices might still have different capabilities (Not just permanent! They also might be tired, or have greasy fingers) so design accordingly.

Though iOS 13.4+ support these media features, it will always match pointer:coarse and hover:none (and their any- counterparts), even when using the new trackpad or the pencil.

The pointer and hover media queries give you information about the primary pointing device. But what about the touchscreen-with-stylus example where you have a coarse and a fine pointing device simultaneously? Even if the user has a stylus, the primary pointing device is still a touch screen, so coarse. For those situations you can use any-hover and any-pointer . This will test if any pointing device exists that matches the criteria.

Less interesting media queries

There are a few more media queries that are not as useful in daily usage but I didn't want to leave out.

the color media query (and it's min-* and max-* variants) lets you detect if the screen your page is being shown on has any color, and if so, how much:

You can also give it a value which translates to the number of bits per color component, so for each of red, green and blue separately. Most modern screens have 8 bits per channel, but 10 bit screens and even 12 bit screens are becoming more common. The value is not the total number of colors, but the bits per color, so don't confuse it with "8-bit color", which is something different. 8 bits per color channel corresponds to a 24-bit color screen.

Somewhat the inverse, monochrome (and it's min-* and max-* variants) lets you detect if the screen is shown on a monochrome (like greyscale) media type. You can again use just the value to detect a monochrome media type:

And like color , it also has an optional value that's the number of bits per pixel. If you test for monochrome: 0 , that will check if the device is not monochrome (so it has colors). monochrome: 1 will detect a device with pixels that are either on or off (like e-paper).

An interesting use-case for monochrome is that you can use it to detect when a page is printed in color or in monochrome:

The grid media query will let you detect when a page is shown in text-only terminals or basic phones with fixed fonts. It's value is either a 0 or a 1, and unlike color or monochrome , you need to explicitly add it:

Upcoming media query features

While all the previous features have pretty good support across modern browsers, there are also many upcoming features that are only supported by a few browsers or that will hopefully be implemented soon.

Please note that some of these are still in a drafting phase, which means they might be changed or scrapped before becoming part of a specification. I'll try to keep this document updated!

Not everyone is lucky enough to have fast, or reliable, or unlimited data plans. Browsers can send the Save-data: on header, and web servers can then choose to send smaller images and videos and disable any form of polling or preloading. Even though turning on the sending of that header is hidden deep in settings (on mobile) or requires a third-party plugin (on desktop), a large number of people still end up use this header.

Unfortunately dealing with this on a web server level is often hard to do, either because you lack access, or the configuration requirements to make it work are just too complex. That's unfortunate because it's potentially very impactful.

Coming up is a prefers-reduced-data: reduce media query, which will let you target this situation in CSS. Though you can do less with that compared to a save-data header (which you could use to send an entirely different website, basically), you can still use it to prevent downloading unneeded fonts and background images, or to request smaller background images.

You can emulate the prefers-reduced-data media query in Polypane using the emulation panel

While we wait on this feature to land, we can already use JavaScript instead to detect the save data preference or a slow connection using the Network Information API:

The Network Information API is available in Chromium browsers and behind a flag in Firefox. It can tell if you saveData is on and gives you rough information on the type of connection. effectiveType takes into account not just the type (wifi, cellular etc) but also how long previous roundtrips to the server took and what the download speed is. There's slow-2g , 2g , 3g and 4g as possible values.

To learn more about how to design for prefers-reduced-data , read our article Creating websites with prefers-reduced-data

User can use this to indicate they prefer to see things on solid colors, usually due to visual impairments making it hard to read text on, for example, background images. But it can also help people with for example dyslexia or concentration problems to read your content easier. Note it doesn't say no-transparency .

Wanting less transparency is not the same as wanting more contrast and should not be lumped together. prefers-contrast and prefers-reduced-transparency are there for different reasons and can be compensated differently for.

Forced-colors (Support in Chromium browsers and Firefox) Available for testing in Polypane

Forced colors, or high contrast, will strip out all your background images if there's text over them and overwrite all your other colors, making everything uniform with the rest of the operating system. This helps people with visual impairments by making all text easier to read for them.

The Polypane homepage shown side-by-side, with the right side showing the site in dark forced color mode.

Those of you that have been doing web development for a bit longer might remember that we could style things with "system colors". That's no longer possible due to security implications, but in the forced colors mode a subset of them are back:

  • CanvasText : the color of text content.
  • LinkText : the color of links.
  • GrayText : the color of disabled content
  • HighlightText : the color of selected text.
  • Highlight : the background color of selected text.
  • ButtonText : the color of a < button > element's text.
  • ButtonFace : the color of a < button > element's background.
  • Canvas : controls the color of the background.

These color names are not here for you to pick and choose, high color mode already overwrite all your text, background, border and button colors. They're there for you to use on other elements (like icons) to make them fit the rest of the site.

Forced-colors has two possible values:

When forced-colors is active, prefers-color-scheme can be used to detect if there is white text on a black background, or black text on a white background.

On Windows, forced-colors will also activate prefers-contrast with a value of more, less or custom depending on whether you have high, low or average contrast between the text and background colors.

It's not always desirable for forced-colors to overwrite all the colors, for example in a color selector on an ecommerce website. To disable forced colors for specific elements you can use the css property forced-color-adjust: none; .

-ms-high-contrast was the implementation of forced colors in the old EdgeHTML version of Edge. It has three possible values to check for, which includes the color scheme:

It similarly has color keywords for you to use, but they're slightly different:

  • WindowText : the color of text content.
  • -ms-hotlight : the color of links.
  • Window : controls the color of the background.

Light-level comes with three possible values: dim , normal and washed . What those mean exactly and when they get triggered is up to the operating system.

Light-level will be dim if the screen is in a dark place, like at night, whereas washed means that it's shown under bright lights or in outdoor conditions with lots of sunlight.

Operating systems nowadays already compensate for these situations by increasing or decreasing brightness, but a website owners we can improve the experience more. In dim situations, you might opt to decrease strong contrast here and there and decrease overall brightness. In washed situations you might want to increase the contrast of all text compared to the background.

Scripting will let you test if JavaScript is available. It has three possible features:

  • none , JavaScript is not available
  • initial-only , JavaScript is only available during page load, but not after
  • enabled , JavaScript is available

Nav controls is used to detect if the page is being viewed in a user agent that has navigation controls (specifically, a back button). It has two possible values:

  • none , meaning there are no navigation controls
  • back , meaning there is are navigation controls and they're visible ("obviously discoverable", according to the spec, which they explain as UI that's visible as opposed to a shortcut or gesture)

This is useful when your website is shown in a webview in an app, where the app might not have its own navigation controls. This way you can still provide a back button or other means of navigating.

Environment blending lets you test whether or not your screen blends with the environment, for example if it's projected onto a piece of glass. There's three potential values:

  • opaque . Like a regular monitor, or paper (think of this as the default)
  • additive . For example, a heads-up display like Hololens. Black is transparent, and white is 100% light.
  • subtractive . For example, an LCD display like a Gameboy screen, embedded in a mirror. Here the opposite happens: 'white' is fully transparent and black has the most contrast.

The screen-spanning media feature (which used to be called just "spanning") is made to support devices with multiple screens. It will tell you if a browser spans multiple screens and if those screens are aligned horizontally or vertically. It has three possible values:

  • none , when the browser does not span multiple screens.
  • single-fold-horizontal , when the browser spans two screens, with the fold horizontally in the middle.
  • single-fold-vertical , when the browser spans two screens, with the fold vertically in the middle.

The specification for this is not yet final, and it might get new names and values, in particularly being more explicit about spanning horizontally or verticallym with integer values to support more than two screens.

Your site will work fine spanning across two screens because the browser will just pretend that it's a single screen, but you can use the values above, along with a new set of env() css environment variables that show you where the fold is so you can lay out things on both screens (For example you could use it to have a list on one screen and a map on the other.)

  • fold-height

These give you an offset for the fold, and you can combine these with calc() to target each screen individually. For Javascript, there's a new api called window.getWindowSegments() that will return an array of your screens. These are static values so won't update if a user rotates their device.

Alongside the new media queries, the latest specifications (4 and 5) also comes with some new notations. They're useful improvements that are slowly finding their way into browsers.

In media query level 4 you can do away with the min-* and max-* versions of media features that have a "range context" (e.g., a min and max version) and instead write them as a simple equation.

If you have both a min-width and a max-width , you can even combine them into one equation:

You can use both < and > as well as <= and >= . The first two will exclude the edges (so (width > 300px) works like (min-width:301px) ), while the last two will include them (and work the same as the min-* and max-* versions).

The range syntax has been supported in Firefox for a long time, Chromium supports it since 104 and Safari since 16.4.

The next few notations aren't supported anywhere yet.

Instead of a comma, you can now also write or just like how you could already write and . The entire query will then evaluate to true as soon as one of them matches.

You can prepend not to the entire media query, but what if you only want to check a single value? You can do that with the not() notation:

Custom media queries let you define a media query once and then use that media query in multiple places without repeating yourself, just like how css custom properties ("variables") work. They even have the same notation.

Here's an example:

Despite all the new features coming out, there's also parts older specifications that are not recommended for use anymore. You might still see them in the wild here and there, but you shouldn't add them to new projects and if you find them in existing projects, try and refactor them.

Device- * media queries

When media queries were first implemented, the main idea was that they reasoned about the device , so there were media features like device-width , device-height and device-aspect-ratio .

But the size of the device is not always the size of the viewport, so styling based on these makes no sense.

The no-preference value for prefers-color-scheme was recently removed from the specification so there will only be dark or light as possible values. They removed it because most browsers implemented this media feature with the default being light and never implemented no-preference anyway. The door is left open for re-introducing it in the future, as well as introducing other color scheme preferences, such as "sepia".

No browser actually supports this feature and it was to be used in tandem with the deprecated tv media type so we'll probably never see support again, but I'll explain it anyway. The scan media query can be used to test for the scanning process that is used to paint an image on a screen (like on a CRT monitor). It has two options:

  • interlace , where odd and even lines are drawn alternately.
  • progressive where all lines are drawn one by one.

progressive is described as a screen that is slower to update and probably fuzzier.

Lastly, I want to point out that you can't just use media queries in CSS, you can reason about them in JavaScript as well. You can do this with the window.matchMedia() function.

The window.matchMedia() function takes a media query string and return a "MediaQueryList" object with information on if that particular media query matches:

The matches value will tell you if the media query evaluates to true . So if you had video that you wanted to autoplay, you could use a matchMedia function to do that only for people that don't have prefers-reduced-motion: reduce :

You can also add a listener to the MediaQueryList object. This will let you respond to changes in the document that cause the media query to go from false to true , or the other way around.

The matchMedia object also used to have an addListener function that you could use for the same purpose, but that has been deprecated.

Polypane lets you test your website in many different screen sizes and against different media queries like prefers-color-scheme , print stylesheets and prefers-reduced-motion .

It's the fastest way to develop and test websites, and you can try it for free !

Build your next project with Polypane

  • Use all features on all plans
  • On Mac, Window and Linux
  • 14-day free trial – no credit card needed

Polypane screenshot

  • Skip to main content
  • Select language
  • Skip to search

Using media queries

-moz-windows-theme, -webkit-transition.

A media query consists of an optional media type and zero or more expressions that limit the style sheets' scope by using media features, such as width, height, and color. Media queries, added in CSS3 , let the presentation of content be tailored to a specific range of output devices without having to change the content itself.

Media queries consist of an optional media type and can, as of the CSS3 specification, contain zero or more expressions, expressed as media features, which resolve to either true or false. The result of the query is true if the media type specified in the media query matches the type of device the document is being displayed on and all expressions in the media query are true.

When a media query is true, the corresponding style sheet or style rules are applied, following the normal cascading rules. Style sheets with media queries attached to their element specifies relationships between the current document and an external resource. Possible uses for this element include defining a relational framework for navigation. This element is most used to link to style sheets."> <link> tags will still download even if their media queries would return false (they will not apply, however).

Unless you use the not or only operators, the media type is optional and the all type will be implied.

Logical operators

You can compose complex media queries using logical operators, including not , and , and only . The and operator is used for combining multiple media features together into a single media query, requiring each chained feature to return true in order for the query to be true. The not operator is used to negate an entire media query. The only operator is used to apply a style only if the entire query matches, useful for preventing older browsers from applying selected styles. If you use the not or only operators, you must specify an explicit media type.

You can also combine multiple media queries in a comma-separated list; if any of the media queries in the list is true, the entire media statement returns true. This is equivalent to an or operator.

The and keyword is used for combining multiple media features together, as well as combining media features with media types. A basic media query, a single media feature with the implied all media type, could look like this:

If, however, you wanted this to apply only if the display is in landscape, you could use an and operator to chain the media features together.

Now the above media query will only return true if the viewport is 700px wide or wider and the display is in landscape. If, however, you only wanted this to apply if the display in question was of the media type TV, you could chain these features with a media type using an and operator.

Now, the above media query will only apply if the media type is TV, the viewport is 700px wide or wider, and the display is in landscape.

comma-separated lists

Comma-separated lists behave like the logical operator or when used in media queries. When using a comma-separated list of media queries, if any of the media queries returns true, the styles or style sheets get applied. Each media query in a comma-separated list is treated as an individual query, and any operator applied to one media query does not affect the others. This means the comma-separated media queries can target different media features, types, and states.

For instance, if you wanted to apply a set of styles if the viewing device either had a minimum width of 700px or was a handheld in landscape, you could write the following:

Above, if I were on a screen device with a viewport width of 800px, the media statement would return true because the first part, interpreted as @media all and (min-width: 700px) would apply to my device and therefore return true, despite the fact that my screen device would fail the handheld media type check in the second media query. Likewise, if I were on a handheld device held in landscape with a viewport width of 500px, while the first media query would fail due to the viewport width, the second media query would succeed and thus the media statement would return true.

The not keyword applies to the whole media query and returns true if the media query would otherwise return false (such as monochrome on a color display or a screen width of 600px with a min-width: 700px feature query). A not will only negate the media query it is applied to and not to every media query if present in a comma-separated list of media queries. The not keyword cannot be used to negate an individual feature query, only an entire media query. For example, the not is evaluated last in the following query:

This means that the query is evaluated like this:

... rather than like this:

As another example, look at the following media query:

It is evaluated like this:

The only keyword prevents older browsers that do not support media queries with media features from applying the given styles:

Media queries are case insensitive. Media queries involving unknown media types are always false.

Media features

Most media features can be prefixed with "min-" or "max-" to express "minimum condition" or "maximum condition" constraints. For example, "max-width:12450px" means the highest condition for applying the styles is, the media have a screen with 12450px width. If the screen is wider than 12450px, the style will not be applied. This avoids using the "<" and ">" symbols, which would conflict with HTML and XML. If you use a media feature without specifying a value, the expression resolves to true if the feature's value is non-zero.

Value: CSS data type is a type of <number> that represents a whole number, whether positive or negative. Integers are used in numerous CSS properties, such as z-index, counter-increment, column-count, grid-column, grid-row, and repeat()."> <integer> Media: media/visual Accepts min/max prefixes: yes

Indicates the number of bits per color component of the output device. If the device is not a color device, this value is zero.

To apply a style sheet to all color devices:

To apply a style sheet to devices with at least 4 bits per color component:

color-index

Indicates the number of entries in the color look-up table for the output device.

To indicate that a style sheet should apply to all devices using indexed color, you can do:

To apply a style sheet to indexed color devices with at least 256 colors:

aspect-ratio

Value: CSS data type, used for describing aspect ratios in media queries, denotes the proportion between two unitless values."> <ratio> Media: media/visual , media/tactile Accepts min/max prefixes: yes

Describes the aspect ratio of the targeted display area of the output device. This value consists of two positive integers separated by a slash ("/") character. This represents the ratio of horizontal pixels (first term) to vertical pixels (second term).

The following selects a special style sheet to use for when the display area is at least as wide as it is high.

This selects the style when the aspect ratio is either 1:1 or greater. In other words, these styles will only be applied when the viewing area is square or landscape.

device-aspect-ratio

Deprecated This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Describes the aspect ratio of the output device. This value consists of two positive integers separated by a slash ("/") character. This represents the ratio of horizontal pixels (first term) to vertical pixels (second term).

The following selects a special style sheet to use for widescreen displays.

This selects the style when the aspect ratio is either 16:9 or 16:10.

device-height

Value: CSS data type represents a distance value. Many CSS properties take <length> values, such as width, margin,  padding, font-size, border-width, text-shadow, and many others."> <length> Media: media/visual , media/tactile Accepts min/max prefixes: yes

Describes the height of the output device (meaning the entire screen or page, rather than just the rendering area, such as the document window).

To apply a style sheet to a document when displayed on a screen that is less than 800 pixels long, you can use this:

device-width

Describes the width of the output device (meaning the entire screen or page, rather than just the rendering area, such as the document window).

To apply a style sheet to a document when displayed on a screen that is less than 800 pixels wide, you can use this:

Value: <mq-boolean> which is an CSS data type is a type of <number> that represents a whole number, whether positive or negative. Integers are used in numerous CSS properties, such as z-index, counter-increment, column-count, grid-column, grid-row, and repeat()."> <integer> that can only have the 0 and 1 value. Media: all Accepts min/max prefixes: no

Determines whether the output device is a grid device or a bitmap device. If the device is grid-based (such as a TTY terminal or a phone display with only one font), the value is 1. Otherwise it is zero.

To apply a style to handheld devices with a 15-character or narrower display:

The height media feature describes the height of the output device's rendering surface (such as the height of the viewport or of the page box on a printer).

Indicates the number of bits per pixel on a monochrome (greyscale) device. If the device isn't monochrome, the device's value is 0.

To apply a style sheet to all monochrome devices:

To apply a style sheet to monochrome devices with at least 8 bits per pixel:

orientation

Value: landscape | portrait Media: media/visual Accepts min/max prefixes: no

Indicates whether the viewport is in landscape (the display is wider than it is tall) or portrait (the display is square or taller than it is wide) mode.

To apply a style sheet only in portrait orientation:

Value: CSS data type, used in media queries, denotes the density of pixels of an output device, i.e., its resolution."> <resolution> Media: bitmap Accepts min/max prefixes: yes

Indicates the resolution (pixel density) of the output device. The resolution may be specified in either dots per inch (dpi) or dots per centimeter (dpcm).

To apply a style sheet to devices with at least 300 dots per inch of resolution:

To replace the old (min-device-pixel-ratio: 2) syntax:

Value: progressive | interlace Media: media/tv Accepts min/max prefixes: no

Describes the scanning process of television output devices.

To apply a style sheet only to progressive scanning televisions:

The width media feature describes the width of the rendering surface of the output device (such as the width of the document window, or the width of the page box on a printer).

If you want to specify a style sheet for handheld devices, or screen devices with a width greater than 20em, you can use this query:

This media query specifies a style sheet that applies to printed media wider than 8.5 inches:

This query specifies a style sheet that is usable when the viewport is between 500 and 800 pixels wide:

Mozilla-specific media features

Mozilla offers several Gecko-specific media features. Some of these may be proposed as official media features.

-moz-mac-graphite-theme

Value: CSS data type is a type of <number> that represents a whole number, whether positive or negative. Integers are used in numerous CSS properties, such as z-index, counter-increment, column-count, grid-column, grid-row, and repeat()."> <integer> Media: media/visual Accepts min/max prefixes: no

If the user has configured their device to use the "Graphite" appearance on Mac OS X, this is 1. If the user is using the standard blue appearance, or is not on Mac OS X, this is 0.

This corresponds to the :-moz-system-metric(mac-graphite-theme) CSS pseudo-class .

-moz-maemo-classic

If the user is using Maemo with the original theme, this is 1; if it's using the newer Fremantle theme, this is 0.

This corresponds to the :-moz-system-metric(maemo-classic) CSS pseudo-class .

-moz-device-pixel-ratio

Value: CSS data type represents a number, being either a whole integer or a fraction."> <number> Media: media/visual Accepts min/max prefixes: yes

Gives the number of device pixels per CSS pixel.

Do not use this feature.

Use the resolution feature with the dppx unit instead. -moz-device-pixel-ratio may be used for compatibility with Firefox older than 16 and -webkit-device-pixel-ratio with WebKit-based browsers that do not support dppx .

See this CSSWG article for compatibility good practices regarding resolution and dppx .

-moz-os-version

Value: windows-win7 | windows-win8 | windows-win10 Media: media/visual Accepts min/max prefixes: no

Indicates which operating system version is currently being used. Currently only implemented on Windows. Possible values are:

  • windows-win7
  • windows-win8
  • windows-win10

This is provided for application skins and other chrome code to be able to adapt to work well with the current operating system version.

-moz-scrollbar-end-backward

If the device's user interface displays a backward arrow button at the end of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the :-moz-system-metric(scrollbar-end-backward) CSS pseudo-class .

-moz-scrollbar-end-forward

If the device's user interface displays a forward arrow button at the end of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the :-moz-system-metric(scrollbar-end-forward) CSS pseudo-class .

-moz-scrollbar-start-backward

If the device's user interface displays a backward arrow button at the beginning of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the :-moz-system-metric(scrollbar-start-backward) CSS pseudo-class .

-moz-scrollbar-start-forward

If the device's user interface displays a forward arrow button at the beginning of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the :-moz-system-metric(scrollbar-start-forward) CSS pseudo-class .

-moz-scrollbar-thumb-proportional

If the device's user interface displays the thumb of scrollbars proportionally (that is, sized based on the percentage of the document that is visible), this is 1. Otherwise it's 0.

This corresponds to the :-moz-system-metric(scrollbar-thumb-proportional) CSS pseudo-class .

-moz-touch-enabled

If the device supports touch events (for a touch screen), this is 1. Otherwise it's 0.

This corresponds to the :-moz-system-metric(touch-enabled) CSS pseudo-class .

You might use this to render your buttons slightly larger, for example, if the user is on a touch-screen device, to make them more finger-friendly.

-moz-windows-accent-color-in-titlebar

In recent Windows versions (e.g. 10), this allows you to detect whether accent colors are enabled in the Windows titlebars. If so, the value is 1, else it is 0.

This is closely related to the Mozilla-specific CSS data type represents a color in the sRGB color space. A color can be described in any of the following ways:"> <color> values -moz-win-accentcolor and -moz-win-accentcolortext , which allow you to access the Windows accent and overlaid text accent colors from CSS.

-moz-windows-classic

If the user is using Windows unthemed (in classic mode instead of using uxtheme), this is 1; otherwise it's 0.

This corresponds to the :-moz-system-metric(windows-classic) CSS pseudo-class .

-moz-windows-compositor

If the user is using Windows with the DWM compositor, this is 1; otherwise it's 0.

This corresponds to the :-moz-system-metric(windows-compositor) CSS pseudo-class .

-moz-windows-default-theme

If the user is currently using one of the default Windows themes (Luna, Royale, Zune, or Aero (including Vista Basic, Vista Advanced, and Aero Glass), this is 1. Otherwise it's 0.

This corresponds to the :-moz-system-metric(windows-default-theme) CSS pseudo-class .

-moz-windows-glass

If the user is using Windows Glass theme, this is 1; otherwise it's 0. Note that this only exists for Windows 7 and earlier.

Value: aero | luna-blue | luna-olive | luna-silver | royale | generic | zune Media: media/visual Accepts min/max prefixes: no

Indicates which Windows theme is currently being used. Only available on Windows. Possible values are:

  • luna-silver

This is provided for application skins and other chrome code to be able to adapt to work well with the current Windows theme.

WebKit media features

-webkit-transform-3d.

Value: CSS data type is a type of <number> that represents a whole number, whether positive or negative. Integers are used in numerous CSS properties, such as z-index, counter-increment, column-count, grid-column, grid-row, and repeat()."> <integer> Media: media/visual Accepts min/max prefixes: no Spec Docs

If supported, the value is 1 , otherwise, the value is 0.

-webkit-transform-2d

Value: CSS data type is a type of <number> that represents a whole number, whether positive or negative. Integers are used in numerous CSS properties, such as z-index, counter-increment, column-count, grid-column, grid-row, and repeat()."> <integer> Media: media/visual Accepts min/max prefixes: no Docs

Browser compatibility

[1] grid media type is not supported.

[2] Supports CSS data type is a type of <number> that represents a whole number, whether positive or negative. Integers are used in numerous CSS properties, such as z-index, counter-increment, column-count, grid-column, grid-row, and repeat()."> <integer> values.

[3] Supports CSS data type represents a number, being either a whole integer or a fraction."> <number> values, as per the spec.

[4] tv media type is not supported.

[5] See WebKit bug 22494 .

[6] Implemented for Web compatibility reasons in Gecko 46.0 (Firefox 46.0 / Thunderbird 46.0 / SeaMonkey 2.43) behind the preference layout.css.prefixes.webkit defaulting to false . See bug 1239799 . Since Gecko 49.0 (Firefox 49 / Thunderbird 49 / SeaMonkey 2.46) layout.css.prefixes.webkit defaults to true .

[7] Implemented as aliases for min--moz-device-pixel-ratio and max--moz-device-pixel-ratio for Web compatibility reasons in Gecko 45.0 (Firefox 45.0 / Thunderbird 45.0 / SeaMonkey 2.42) (see bug 1176968 ) behind the preferences layout.css.prefixes.webkit and layout.css.prefixes.device-pixel-ratio-webkit , defaulting to false . Since Gecko 49.0 (Firefox 49 / Thunderbird 49 / SeaMonkey 2.46) layout.css.prefixes.webkit defaults to true .

  • CSS 3 media query specification
  • Media types
  • Using media queries from code /script
  • List of mobile and tablet viewport sizes with pixel ratios
  • CSS Animations Between Media Queries by David Walsh
  • @media (-webkit-transform-3d)

Document Tags and Contributors

  • comma-seperated list
  • media features
  • Media Queries
  • NeedsBrowserCompatibility
  • NeedsMobileBrowserCompatibility
  • Responsive Design

CSS Tutorial

Css advanced, css responsive, css examples, css references, responsive web design - media queries, what is a media query.

Media query is a CSS technique introduced in CSS3.

It uses the @media rule to include a block of CSS properties only if a certain condition is true.

If the browser window is 600px or smaller, the background color will be lightblue:

Add a Breakpoint

Earlier in this tutorial we made a web page with rows and columns, and it was responsive, but it did not look good on a small screen.

Media queries can help with that. We can add a breakpoint where certain parts of the design will behave differently on each side of the breakpoint.

safari specific media query

Use a media query to add a breakpoint at 768px:

When the screen (browser window) gets smaller than 768px, each column should have a width of 100%:

Advertisement

Always Design for Mobile First

Mobile First means designing for mobile before designing for desktop or any other device (This will make the page display faster on smaller devices).

This means that we must make some changes in our CSS.

Instead of changing styles when the width gets smaller than 768px, we should change the design when the width gets larger than 768px. This will make our design Mobile First:

Another Breakpoint

You can add as many breakpoints as you like.

We will also insert a breakpoint between tablets and mobile phones.

safari specific media query

We do this by adding one more media query (at 600px), and a set of new classes for devices larger than 600px (but smaller than 768px):

Note that the two sets of classes are almost identical, the only difference is the name ( col- and col-s- ):

It might seem odd that we have two sets of identical classes, but it gives us the opportunity in HTML , to decide what will happen with the columns at each breakpoint:

HTML Example

For desktop:

The first and the third section will both span 3 columns each. The middle section will span 6 columns.

For tablets:

The first section will span 3 columns, the second will span 9, and the third section will be displayed below the first two sections, and it will span 12 columns:

Typical Device Breakpoints

There are tons of screens and devices with different heights and widths, so it is hard to create an exact breakpoint for each device. To keep things simple you could target five groups:

Orientation: Portrait / Landscape

Media queries can also be used to change layout of a page depending on the orientation of the browser.

You can have a set of CSS properties that will only apply when the browser window is wider than its height, a so called "Landscape" orientation:

The web page will have a lightblue background if the orientation is in landscape mode:

Hide Elements With Media Queries

Another common use of media queries, is to hide elements on different screen sizes:

Change Font Size With Media Queries

You can also use media queries to change the font size of an element on different screen sizes:

Variable Font Size.

Css @media reference.

For a full overview of all the media types and features/expressions, please look at the @media rule in our CSS reference .

Get Certified

COLOR PICKER

colorpicker

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

[email protected]

Top Tutorials

Top references, top examples, get certified.

Media Queries: Range Syntax

Syntax improvements to make media queries using features that have a "range" type (like width or height) less verbose. Can be used with ordinary mathematical comparison operators: > , &lt; , >= , or &lt;= .

For example: @media (100px &lt;= width &lt;= 1900px) is the equivalent of @media (min-width: 100px) and (max-width: 1900px)

  • 4 - 103 : Not supported
  • 104 - 121 : Supported
  • 122 : Supported
  • 123 - 125 : Supported
  • 12 - 103 : Not supported
  • 3.1 - 16.3 : Not supported
  • 16.4 - 17.3 : Supported
  • 17.4 : Supported
  • TP : Supported
  • 2 - 62 : Not supported
  • 63 - 122 : Supported
  • 123 : Supported
  • 124 - 126 : Supported
  • 9 - 90 : Not supported
  • 91 - 105 : Supported
  • 106 : Supported
  • 5.5 - 10 : Not supported
  • 11 : Not supported

Chrome for Android

Safari on ios.

  • 3.2 - 16.3 : Not supported

Samsung Internet

  • 4 - 19.0 : Not supported
  • 20 - 22 : Supported
  • 23 : Supported
  • all : Not supported

Opera Mobile

  • 10 - 12.1 : Not supported
  • 73 : Supported

UC Browser for Android

  • 15.5 : Not supported

Android Browser

  • 2.1 - 4.4.4 : Not supported

Firefox for Android

  • 13.1 : Not supported

Baidu Browser

  • 13.18 : Not supported

KaiOS Browser

  • 2.5 : Not supported
  • 3 : Supported

Working with JavaScript Media Queries

Avatar of Marko Ilic

📣 Freelancers, Developers, and Part-Time Agency Owners: Kickstart Your Own Digital Agency with UACADEMY Launch by UGURUS 📣

What’s the first thing that comes to mind when you think of media queries? Maybe something in a CSS file that looks like this:

CSS media queries are a core ingredient in any responsive design. They’re a great way to apply different styles to different contexts, whether it’s based on viewport size, motion preference, preferred color scheme, specific interactions and, heck, even certain devices like printers, TVs and projectors, among many others.

But did you know that we have media queries for JavaScript too? It’s true! We may not see them as often in JavaScript, but there definitely are use cases for them I have found helpful over the years for creating responsive plugins, like sliders. For example, at a certain resolution, you may need to re-draw and recalculate the slider items.

Working with media queries in JavaScript is very different than working with them in CSS, even though the concepts are similar: match some conditions and apply some stuff.

Using matchMedia()

To determine if the document matches the media query string in JavaScript, we use the matchMedia() method. Even though it’s officially part of the CSS Object Model View Module specification which is in Working Draft status, the browser support for it is great going as far back as Internet Explorer 10 with 98.6% global coverage.

This browser support data is from Caniuse , which has more detail. A number indicates that browser supports the feature at that version and up.

Mobile / Tablet

The usage is nearly identical to CSS media queries. We pass the media query string to matchMedia( ) and then check the .matches property.

The defined media query will return a MediaQueryList object. It is an object that stores information about the media query and the key property we need is .matches . That is a read-only Boolean property that returns true if the document matches the media query.

That’s the basic usage for matching media conditions in JavaScript. We create a match condition ( matchMedia() ) that returns an object ( MediaQueryList ), check against it ( .matches ), then do stuff if the condition evaluates to true. Not totally unlike CSS!

But there’s more to it. For example, if we were change the window size below our target window size, nothing updates the way it will with CSS right out of the box. That’s because .matches is perfect for one-time instantaneous checks but is unable to continuously check for changes. That means we need to…

Listen for changes

 MediaQueryList has an  addListener() (and the subsequent removeListener() ) method that accepts a callback function (represented by the .onchange event) that’s invoked when the media query status changes. In other words, we can fire additional functions when the conditions change, allowing us to “respond” to the updated conditions.

The one-two punch of matchMedia() and MediaQueryList gives us the same power to not only match media conditions that CSS provides, but to actively respond to updated conditions as well.

When you register an event listener with addListener() it won’t fire initially. We need to call the event handler function manually and pass the media query as the argument.

The old way of doing things

For the sake of context — and a little nostalgia — I would like to cover the old, but still popular, way of doing “media queries” in JavaScript (and, yes, those quotes are important here). The most common approach is binding a resize event listener that checks window.innerWidth or window.innerHeight .

You’ll still see something like this in the wild:

Since the resize event is called on each browser resize, this is an expensive operation! Looking at the performance impact of an empty page we can see the difference.

safari specific media query

An even simpler way to see the difference is with the help of a console log.

safari specific media query

Even if we look past the performance issues, resize is restrictive in the sense that it doesn’t let us write advanced media queries for things like print and orientation. So, while it does mimic “media query” behavior by allowing us to match viewport widths, it’s incapable of matching much of anything else — and we know that true media queries are capable of so much more.

That’s a look at media queries in JavaScript! We explored how matchMedia() allows us to define media conditions and examined the MediaQueryList object that lets us do one-time ( .matches ) and persistent ( addListener() ) checks against those conditions so that we can respond to changes ( .onchange ) by invoking functions.

We also saw the “old” way of doing things by listening for resize events on the window. While it’s still widely used and a totally legit way to respond to changes to the size of the window.innerWidth , it’s unable to perform checks on advanced media conditions.

To finish the article here is a useful example that is not achievable in the old way. Using a media query I will check if the user is in the landscape mode. This approach is common when developing HTML5 games and is best viewed on a mobile device.

Thank you for explaining this useful way of using js media quiries.

I like it, I was always using the “old” method

.match is not necessary to check a Boolean

How can this be used in React? I’ve been looking for an elegant way to make my components responsive without using css. I don’t fancy calling myself a React dev and still using css media queries instead of all js. Please weigh in on this. Thanks

You can use the useState hook and bind the state set function to the event listener. Therefore, it will set the value on each change and the state will be reactive. Just add the initial check and setup in the useEffect hook.

Just an idea, I don’t use React a lot.

I am a React developer, but I still think using CSS media queries instead of JS has better performance than waiting for the browser/component to be mounted and getting the viewport width/height after that.

There is no doubt about what is better, they shouldn’t be event compared. This is just a new optimized way to solved old problems, resize event plus checking the width of the browser.

Today I learned about events comes along with match media….thanks Amit for that…orientation media in its own has some issues I think…it will not work properly when virtual keypad is open….

That is true, unfortunately, that is an old CSS problem. Here is an explanation of why.

If you look at the spec provided by W3 it says:

The ‘orientation’ media feature is ‘portrait’ when the value of the ‘height’ media feature is greater than or equal to the value of the ‘width’ media feature. Otherwise ‘orientation’ is ‘landscape’.

Spec: https://www.w3.org/TR/css3-mediaqueries/#orientation

This is why this problem can occur sometimes. This can be improved by writing a different query like using min-aspect-ratio

Base on your post, I created little module, can be use in a good way as we normally needs in developments. https://github.com/bzaman/JavaScript-Media-Queries/blob/master/README.md

Thanks for an article. On improvement can be added here. Rather using specific method addListener which is marked as deprecated, we can use native Event interface and just set it in this way mediaQuery.addEventListener('change', handleTabletChange) .

Deprecated is brought up a lot for addListener but actually it is not, AFAIK. Even if you check the MDN page it doesn’t mark it as one.

Looking at the CSSWG dom they state:

For backwards compatibility, the addListener() and removeListener() methods are basically aliases for addEventListener() and removeEventListener(), respectively, and the change event masquerades as a MediaQueryList.

This is how I use it, basically an aliase that is backwards compatible.

But you are not wrong, adding an event listener for change is what is actually happening and your code will work.

@marco it is now: https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener#browser_compatibility

Sorry for the post spam, but I just saw now that addListener is supported in IE10 and up while the addEventListener is also supported in IE9, which seems to actually broaden the support.

Am I missing something or does the resize total 3498? Good article though.

Well, someone has a sharp eye. Great catch. It is because numbers are float and we are only seeing interger. When summed it added up to a 1 (I guesses).

What about using CSS variables? Something like that:

@media (min-width: 450px) { :root { –actualMedia: small; } }

and then reading value of –actualMedia variable in JS:

if (getComputedStyle(document.documentElement) .getPropertyValue(‘–actualMedia’) .trim() === “small”) { // … }

I saw this solution some time ago. Back then it was something like body:after {content: "mq-small" and the new one with CSS Custom Properties is even better but won’t work in IE 11. But I’not sure which solution is better from performance perspective?

Some time ago I found about this as well and I created a library to help using matchMedia across the board easily, if you want to check it out: https://github.com/enmanuelduran/mediaquerysensor

what is e in the function?

@Mohammed that is the event object, in this case the object return in mediaQuery

In a standard use of @media we can do something like this: @media only screen and (max-width: 479px) and (orientation: portrait) { // CSS } @media only screen and (min-width: 480px) and (max-width: 768px) { // CSS } @media only screen and (min-width: 769px) and (max-width: 1280px) { // CSS } @media only screen and (min-width: 1281px) and (max-width: 1599px) { // CSS }

Can something similar be done with your “matchMedia” approach? Your example only shows one resolution (min-width: 768px) so I’m left wondering if this is a limitation. Would like to know if this is possible. Thanks!

Thanks for this post, it helped me a lot today.

I would suggest just an update as “addListener” is deprecated.

Best regards and thanks again.

safari specific media query

Help | Advanced Search

Computer Science > Computer Vision and Pattern Recognition

Title: query-guided prototype evolution network for few-shot segmentation.

Abstract: Previous Few-Shot Segmentation (FSS) approaches exclusively utilize support features for prototype generation, neglecting the specific requirements of the query. To address this, we present the Query-guided Prototype Evolution Network (QPENet), a new method that integrates query features into the generation process of foreground and background prototypes, thereby yielding customized prototypes attuned to specific queries. The evolution of the foreground prototype is accomplished through a \textit{support-query-support} iterative process involving two new modules: Pseudo-prototype Generation (PPG) and Dual Prototype Evolution (DPE). The PPG module employs support features to create an initial prototype for the preliminary segmentation of the query image, resulting in a pseudo-prototype reflecting the unique needs of the current query. Subsequently, the DPE module performs reverse segmentation on support images using this pseudo-prototype, leading to the generation of evolved prototypes, which can be considered as custom solutions. As for the background prototype, the evolution begins with a global background prototype that represents the generalized features of all training images. We also design a Global Background Cleansing (GBC) module to eliminate potential adverse components mirroring the characteristics of the current foreground class. Experimental results on the PASCAL-$5^i$ and COCO-$20^i$ datasets attest to the substantial enhancements achieved by QPENet over prevailing state-of-the-art techniques, underscoring the validity of our ideas.

Submission history

Access paper:.

  • Download PDF
  • HTML (experimental)
  • Other Formats

license icon

References & Citations

  • Google Scholar
  • Semantic Scholar

BibTeX formatted citation

BibSonomy logo

Bibliographic and Citation Tools

Code, data and media associated with this article, recommenders and search tools.

  • Institution

arXivLabs: experimental projects with community collaborators

arXivLabs is a framework that allows collaborators to develop and share new arXiv features directly on our website.

Both individuals and organizations that work with arXivLabs have embraced and accepted our values of openness, community, excellence, and user data privacy. arXiv is committed to these values and only works with partners that adhere to them.

Have an idea for a project that will add value for arXiv's community? Learn more about arXivLabs .

IMAGES

  1. ついにSafariも。 media queryの範囲指定をより直感的に書ける記法が全ブラウザ対応へ

    safari specific media query

  2. Media Query CSS: entenda a estrutura e saiba como usar!

    safari specific media query

  3. CSS3

    safari specific media query

  4. How to Search a Webpage for Specific Text in Safari on iPhone and iPad

    safari specific media query

  5. Media Query CSS: entenda a estrutura e saiba como usar!

    safari specific media query

  6. The New CSS Media Query Range Syntax

    safari specific media query

VIDEO

  1. Running Safari 16 on Windows is EASY!!!

  2. How to use Safari on iPhone

  3. Learn how to use Media queries & Container queries

  4. How To Delete Specific Websites From Safari History

  5. How to Block Specific Sites In Safari on iPhone or iPad

  6. CSS Media Queries

COMMENTS

  1. css

    I want the media to work only on safari for a screen of 1280px This work in all browser, but i want only safari @media screen and (width: 1280px){ } ... browser specific CSS and JavaScript hacks. Share. Improve this answer. ... How to set media query for safari web browser. 1. Css media queries not works in Safari browser. 1 (CSS) Media query ...

  2. Is there a way to apply styles to Safari only?

    By the way, for any of you guys that just need to target Safari on mobiles, just add a media query to this hack: _::-webkit-full-page-media, _:future, :root .safari_only {. padding: 10px; //or any property you need. And don't forget to add the .safari_only class to the element you want to target, example: @media {.

  3. Media Queries for Standard Devices

    After many frustrating hours I went looking and found this question on Stack Overflow, Media query ipad vs iphone4. The media queries are being used to specifically target a device width, pixel density (css ratio) and the orientation. Leaving very little for one device to use another stylesheet not intended for it.

  4. CSS3

    CSS3 Media Query to target only Internet Explorer (from IE6 to IE11+), Firefox, Chrome, Safari and/or EdgeA set of useful CSS3 media queries to target only specific versions of the various browsers: Internet Explorer, Mozilla Firefox, Google Chrome, Apple Safari and Microsoft Edge. February 27, 2018March 11, 2018 - by Ryan - 6 Comments. 161.4K.

  5. How to Craft Browser Specific CSS Code

    For example, if your CSS code includes a few media queries, you'll need to include the following snippet to target specific Safari browsers: ... If your CSS code is targeting media queries in other browsers, the following additions will create Firefox-specific media query code: For Firefox versions = 3: @media \0 all {}

  6. A Complete Guide to CSS Media Queries

    A Complete Guide to CSS Media Queries. Andrés Galante on Oct 2, 2020 (Updated on Oct 19, 2022 ) Media queries can modify the appearance (and even behavior) or a website or app based on a matched set of conditions about the user's device, browser or system settings. CSS Media queries are a way to target browser by certain characteristics ...

  7. @media

    In JavaScript, @media can be accessed via the CSS object model interface CSSMediaRule. The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the ...

  8. Using media queries

    A media query is composed of an optional media type and any number of media feature expressions, which may optionally be combined in various ways using logical operators.Media queries are case-insensitive. Media types define the broad category of device for which the media query applies: all, print, screen.The type is optional (assumed to be all) except when using the not or only logical ...

  9. CSS3 Media Queries Browser Compatibility On Safari

    CSS3 Media Queries is Fully Supported on Safari. ... CSS Media Queries is a new CSS-specific technology created to apply styles based on media information. They can be used to target devices that are larger or smaller than a specific size, devices which have enough bandwidth to handle the required media and more. ...

  10. The New CSS Media Query Range Syntax

    The Media Queries Level 4 specification has introduced a new syntax for targeting a range of viewport widths using common mathematical comparison operators, like , and =, that make more sense syntactically while writing less code for responsive web design. ... evaluating whether the viewport width is greater than or equal to a specific value ...

  11. WebKit Features in Safari 16.1

    Responsive web design techniques, including the use of CSS media queries and container queries, are key. There's never been a single "tablet size" for layout, and now that's more true than ever. ... Safari 16.1 adds support for capturing a specific Safari window with getDisplayMedia().

  12. FabioRosado

    After testing different things and playing around with the media query, I've come to the final solution. I've also added a rule to trigger the CSS only when the screen is smaller than 900px high, because we don't want the menu to be broken on a larger screen. css. Copy. 1@medianot all and(max-height:899px)and(min-resolution:.1dpi){.

  13. I want my own media queries in browsers

    Build our own domain-specific media queries for development. The benefit of getting ahead of browser support for media queries your stylesheets is self-explanatory, and checking e.g. Safari-specific media queries in another browser is just convenient, but it's the last category that is really exciting to me.

  14. The complete guide to CSS media queries

    Inverted colors (Safari only) This media query indicates that the operating system has inverted all colors. The operating system in this instance is MacOs, the only operating system that supports this (and conversely, only Safari supports this media query). ... To disable forced colors for specific elements you can use the css property forced ...

  15. Using media queries

    A media query consists of an optional media type and zero or more expressions that limit the style sheets' scope by using media features, such as width, height, and color. Media queries, added in CSS3, let the presentation of content be tailored to a specific range of output devices without having to change the content itself.. Syntax. Media queries consist of an optional media type and can ...

  16. Responsive Web Design Media Queries

    Add a Breakpoint. Earlier in this tutorial we made a web page with rows and columns, and it was responsive, but it did not look good on a small screen. Media queries can help with that. We can add a breakpoint where certain parts of the design will behave differently on each side of the breakpoint. Desktop.

  17. Media Queries: Range Syntax

    Media Queries: Range Syntax. - CR. Syntax improvements to make media queries using features that have a "range" type (like width or height) less verbose. Can be used with ordinary mathematical comparison operators: >, <, >=, or <= . For example: @media (100px <= width <= 1900px) is the equivalent of @media (min-width: 100px) and (max-width ...

  18. javascript

    This works on all major browsers except, as I just found out, for Safari. Is there another way to enable or disable a media query rule? Note: Using the code above enables and disables the media query by saying, "If the browser is not less than 0px wide then enable this query" and "Unless the browser is 99999px wide do not enable these styles".

  19. Working with JavaScript Media Queries

    The usage is nearly identical to CSS media queries. We pass the media query string to matchMedia() and then check the .matches property. // Define the query const mediaQuery = window.matchMedia('(min-width: 768px)') The defined media query will return a MediaQueryList object. It is an object that stores information about the media query and the ...

  20. Query-guided Prototype Evolution Network for Few-Shot Segmentation

    Download PDF HTML (experimental) Abstract: Previous Few-Shot Segmentation (FSS) approaches exclusively utilize support features for prototype generation, neglecting the specific requirements of the query. To address this, we present the Query-guided Prototype Evolution Network (QPENet), a new method that integrates query features into the generation process of foreground and background ...

  21. css

    @media only screen and (min-width: 768px) and (max-width:1199px) {} I want to put Media query only for safari browser for given Size of device. @media screen and (-webkit-min-device-pixel-ratio:0... Stack Overflow. About; ... CSS Media Queries for specific iPads. Hot Network Questions

  22. All media queries for iPhone 15 (Pro, Max, Plus, Mini) and older ones

    Here you'll find a media query for all iPhones. Most media queries target multiple devices. iPhone 15 and 15 Pro. For iPhone 14 Pro, iPhone 15 and iPhone 15 Pro: /* 1179×2556 pixels at 460ppi */ @media only screen and (width: 393px) and (height: 852px) and (-webkit-device-pixel-ratio: 3) { }