Mastering CSS Media Queries: Optimizing for Retina & Touch Devices

Learn how to use advanced CSS media queries to optimize sliders for Retina iPhones, high-DPI devices, and hybrid touchscreens.

When building responsive websites, CSS media queries are your best friend. They let you fine-tune layouts for different devices, screen sizes, resolutions, and input types. But sometimes media queries can look complicated — especially when dealing with device widths, pixel ratios, and hover/pointer detection.

In this post, we’ll break down three CSS media queries that are often used to optimize sliders (.ftslider) for iPhones, high-density screens, and hybrid touch devices. By the end, you’ll understand exactly what each query targets, why it’s written that way, and how it affects your design.

Targeting iPhone X–Style Devices

@media only screen and (min-device-width: 375px) and (max-device-width: 812px) 
and (-webkit-min-device-pixel-ratio: 3) {
  .ftslider { height: calc(90vh - 85px); }
}

The above @media query targets iPhone X–style devices (and similar), because:

  • min-device-width: 375px – the device width is at least 375px.
  • max-device-width: 812px – the device width is at most 812px.
    • This matches iPhones in the 375×812 portrait range (like iPhone X, XS, 11 Pro, etc.).
  • -webkit-min-device-pixel-ratio: 3 → ensures the device has a Retina 3x screen density.

Handling High-Resolution Displays (Cross-Browser)

@media only screen and (-webkit-min-device-pixel-ratio: 3),
only screen and (-o-min-device-pixel-ratio: 3/1),
only screen and (min-resolution: 458dpi),
only screen and (min-resolution: 3dppx) {
  .ftslider { height: calc(90vh - 85px); }
}

This @media query targets high-resolution displays (3x pixel density or higher), but in a cross-browser compatible way:

  • -webkit-min-device-pixel-ratio: 3 – WebKit (Safari, Chrome).
  • -o-min-device-pixel-ratio: 3/1 – Opera (old syntax).
  • min-resolution: 458dpi – very high DPI screens (approx 3× standard 96dpi).
  • min-resolution: 3dppx – modern way to express “3 device pixels per CSS pixel”.

Hybrid Devices: Hover + Coarse Pointer

@media only screen and (hover: hover) and (pointer: coarse) {
  .ftslider { height: calc(85vh - 55px); }
}

It targets devices that support hover and use a coarse pointer (e.g., touch + stylus hybrids).

Why This Matters

  • Better UX: Users on high-DPI devices get clean, non-clipped layouts.
  • Cross-platform support: Android, iOS, tablets, and hybrid devices all behave predictably.
  • Future-proofing: By writing broad yet precise queries, your design adapts to new device types.

Conclusion

Media queries may look intimidating at first glance, but each one has a specific purpose. In this case, they ensure sliders adapt smoothly across iPhones, high-DPI displays, and hybrid touch devices.

When building responsive designs, don’t just think in terms of width and height – consider pixel density, hover ability, and pointer type. That’s the key to delivering a seamless user experience on any screen.

How to Detect Unused CSS Selectors and Remove Them from Your Website

Improve website performance by identifying and removing unused CSS selectors. Learn effective tools and methods to clean up your stylesheets.

During the development, we forget to remove selectors, which have been changed during the different phases of the website, Which makes stylesheet file so large. Due to which, stylesheets load slower, which makes the website load slower. So, this is necessary to remove unused css rules from stylesheets to make a website load faster.

There are so many online tools, Firefox Extension as well as commercial products to do that.

Firefox Development Tool: Dust-Me Selectors

It scans your HTML pages and find the unused CSS selectors. It takes all CSS selectors from all stylesheets attached to the page you are viewing and then scan that page to find the unused selectors. It stores data separately for each website you viewed.

Disadvantage: It just gives you the unused selectors, but not providing the updated stylesheet.

Dead Weight: Ruby Gem

It is a CSS coverage tool and only works for rails website. You need to provide a set of stylesheets and URLs, from which it provides a list of selectors which can be “safely” deleted. You can manually remove them from the stylesheet using that list.

You can watch the screen-cast on Dead Weight Introduction at http://railscasts.com/episodes/180-finding-unused-css

Unused-CSS.com: Online Tool

It asks for an online URL to check. From the URL, It scans all CSS files and show the results separately for each stylesheet with graphs. Currently it scans only homepage, but if you need whole website results, you need to provide your e-mail address and it will send the results to you in email.

Helium CSS: Javascript Tool

It is a javascript-based tool and runs from the browser. It is a used for discovering unused selectors across many pages on a web site. It accepts only list of URLs, parses each URL provided and build a list of stylesheets. Using this list of stylesheets and URLs, it generates a list of unused selectors not used in any of the URL provided.

TopStyle 5: Windows Application

It is an HTML Editor, which includes a tool named Style Sweeper. Style sweeper can remove white spaces and blank lines, sort according to Class, Element, ID and also combines multiple selectors. It will also combine repeated property as well as selectors if they are same. But it’s a commercial product costs $80 (USD).

LiquidCity CSS Cleaner: PHP Script

It uses regular expressions to check any HTML page specified by you, generates the report with unused selectors for that HTML page only. From that report, you can manually remove them from the stylesheet.

There are so many other tools available. We will introduce them very soon.