Rectangle 27 0

css Should I use max device width or max width?

I generally use 3 breakpoints: one for phones, one for tablet and one for desktop. The desktop and often at least the landscape portrait are fixed and the tablet portrait and below are liquid. This combination of adaptive and responsive allows the desktop to behave like a desktop site while keeping me from needed to layout 10-odd separate fixed-width mobile device layouts. The text doesn't reflow on mobile devices because the viewport can't be resized.

I personally use min/max-device-width because I prefer to follow desktop document conventions that have decades of precedence. Not all documents you open on the internet are going to behave this way on a desktop, nor are other types of documents or applications that you load on your desktop. Pages designed before the dominance of mobile, just like MS Word, Photoshop, etc. hold their scroll positions and do not change their layouts allowing users to keep track of content within the page flow when performing the unrelated task of window management.

I was also using min/max-device-width but then to my horror a client set up hotjar, which creates little videos of user interaction with your site, and I realized the new android 6 samsung galaxy 6 was treating the pixel count of min/max-device-width as the actual screen pixels, not the css pixels, which of course made the page go off the screen. In our case what happened was that the users were getting with these 4x pixel density screens a mixture of mobile and desktop css. Personally I don't believe responsive has any place on a well done desktop display, bad for users. So be careful.

If you use max-width, when you change the size of the browser window on your desktop, you might be shown mobile-orientated styling, such as touch-friendly elements and menus and that kind of thing.

It's shocking to me that it seems to be popular opinion that this is desirable. I haven't figured out if fluid/liquid design before mobile was considered bad for the wrong or the right reasons. It appears to me that this is just a fancier version of liquid layout, but one that designers are embracing for some reason.

Paul, it required some research to figure out what's going on. Josh's answer is in my opinion wrong, as is google's. The notion that desktops should be responsive is just a fad being fueled by groups like google and the various one size fits all css frameworks. Our issue came from bad hotjar programming, period. My trigger points basically treat any large screened device as a desktop, with a few tweaks, then go down to where the view port would only be a mobile device. For users looking for clarity, I'd consider paul's answer as correct, and the fad driven responsive answers as wrong.

There are some mobiles where the viewport can be resized - for example windows allows "snapping" multiple apps onto the screen, and some android phones have support for windowing to see two apps at once. Objectively I don't see why you wouldn't want a tablet style layout on a smaller screened desktop, but subjectively it depends on the layout.

When the design community at large chose to side with fixed layouts over liquid in the mid 2000s, it was because text reflows impeded legibility often resulting in widows and other typogrphical artifacts. Additionally, maintaining the codebase was often tricky from design to design to keep elements from colliding etc. The only difference between liquid layouts and responsive design is that responsive, due to better browsers and the proliferation of masonry-like frameworks make it easier to accomplish.

Rectangle 27 0

css Should I use max device width or max width?

<meta name="viewport" content="width=device-width, initial-scale=1">

Google Developers - Web Fundamentals - Responsive CSS media queries

@JohnMagnolia It took a while, but I completely re-wrote the answer. Thanks for reminding me :) Feedback is appreciated.

Agree with everything your saying but forgetting the backwards compatibility side of it, that wont be relevant in a few years. Why should a desktop site work differently because we now have mobiles?

Due to all the different possible screen resolutions and pixel densities a given device can have, a pixel is not a pixel because there are several things to take into consideration (zoom, pixel density, screen resolution and size, device orientation, aspect ratio, etc..). In this case, a pixel is actually referred to as a "optical reference unit" rather than a physic hardware pixel.

Fortunately, you can specify a viewport meta tag in the <head> section of your document in order to control the width and scaling of the browser's viewport. If this tag has a content value of width=device-width, the screen's width will match the device independent pixels and will ensure that all the different devices should scale and behave consistently.

I agree with John M, google is wrong, I've personally found their responsive design 'documentation' some of the worst fad driven stuff out there, given creedence only because the kids who write it are employed by google. I initially upvoted this, but the answer is wrong in my opinion, just because more and more sites are ruining their desktop user experience, totally non-necessarily to fit a one size fits all responsive css framework (done only to cut dev time in my opinion), does not mean you have to ruin your desktop user's experience. We don't do that, and have increased conversions by 10x.

I just don't think a mobile site should ever be displayed on a desktop. You should be able to resize to browser to any width and use the horizontal scrollbar. Say you wanted to compare a section of 2 sites but hide the sidebar, you would open in 2 windows and resize side by side

If you're making a responsive website, you will probably want to use min-width/max-width rather than min-device-width/max-device-width in order to target a wider range of screen sizes.

In addition, using *-device-width can prevent content from adapting on desktops or other devices that allow windows to be resized because the query is based on the actual device size, not the size of the browser window.

In other words, if you are using max-device-width, you will not see different media queries applied when resizing your desktop browser, because unlike max-width, only the device's actual full screen size is taken into consideration; not the current size of the browser window.

In terms of media queries, you will probably want to use max-width rather than max-device-width, since max-width will target the viewport (current browser window), whereas max-device-width will target the device's actual full screen size/resolution.

It is also possible to create queries based on *-device-width; though this practice is strongly discouraged.

Remember to specify a viewport meta tag in the <head> section of your document:

The difference is subtle but very important: min-width is based on the size of the browser window, whereas min-device-width is based on the size of the screen. Unfortunately some browsers, including the legacy Android browser may not report the device width properly and instead report the screen size in device pixels instead of the expected viewport width.

This makes a huge difference if you're trying to create an adaptive layout because the site won't be responsive when resizing the browser. In addition, if you're using max-device-width the media queries you're using to target devices with smaller screens will not apply to desktops even when resizing the browser window down to match said smaller screen size.