Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Unused CSS Stages Media Queries Device-Specific Media Queries: Part 1

Derek Zinger
Derek Zinger
3,337 Points

Device pixel density of 2 means 4 device pixels per logical pixel

So, if the Retina iPhone has a resolution of 640 x 1136

with a pixel density of 2

then its logical resolution is 320 x 568

Therefore, one logical pixel equals 4 device pixels, right? The logical pixel is subdivided into two vertical pixels and two horizontal pixels.

Why is "4" not the correct answer in the quiz? I'm irked that I have to rewatch 20 minutes of video for a concept that I'm pretty sure I understand.

3 Answers

I believe that for the retina display, two physical pixels on the screen equate to 1 css pixel. I don't think you should think about both horizontal and vertical direction together. Rather, two physical pixels in the horizontal direction equal 1 css pixel in the horizontal. Same for vertical.

Was this the question?

If a device has a pixel-ratio of 2, then 1 CSS pixel is displayed as ___________ physical pixel(s) on screen.

If it is then I think it would help if you consider horizontal and vertical separate, not together.

Derek Zinger
Derek Zinger
3,337 Points

Thanks for replying, Jason. That was indeed the question.

You're right in that Treehouse has been referring to 2 Retina pixels per every CSS pixel. However, I came into this already understanding Retina pixels in the 2D way (ie. 4:1). I get why they're asking for an answer of 2, but you have to admit that 4 is also a perfectly correct answer, is it not?

Hi Derek,

I could not find any source that referred to it as 4 to 1. Do you remember where you got that idea from? I can see why you're getting 4:1. There's 4 times as many pixels if you multiply the width and height to get total number of pixels. But resolution is measured linearly. I tried to find a source that definitively says this but was unable too. Many sources though said the ratio was 2 for something like the retina display.

So it's not just Treehouse that is referring to it this way.

Here's a link that has some info on the different units and how they all fit together.

One thing to note is that it mentions that 96dpi is equivalent to a device pixel ratio of 1. 96dpi is dots per inch which is a linear measurement. So device pixel ratio is also a linear measurement.

As you'll find in the article, device-pixel-ratio isn't in the standard. We should move towards using resolution instead. The w3c created a new unit called dppx which is dots per pixel unit. This is meant to replace device-pixel-ratio. A device-pixel-ratio of 2 is equivalent to 2dppx.

I hope this clears it up for you a little better.

Derek Zinger
Derek Zinger
3,337 Points

Thanks for the detailed reply, Jason. I can also understand it as a 1:2 ratio. It was Apple's original publicity for the Retina display that had me thinking on two axes, though. They showed a pixel being subdivided into four.