27 Mar 2020
With the help of CSS3 and mediaqueries you can change the layout of your website based on the detected screen size of the device (be it a computer screen, tablet, smartphone,…). But what are the current guidelines and best practices? Read on.
First we will define our so called ‘breakpoints’ in our CSS file. These breakpoints target the screen resolution, and more specifically the width.
We could instruct our web site to act as follows:
That depends on the content of your website. Very important information should be ‘above the fold’ which means: visible without scrolling. So it’s always good to know the available height on the most used devices, to avoid cutting off banners in the middle or putting that very important call-to-action button out of sight.Why not target the device?
I’m not saying you never should. Maybe in some particular cases you’d want to target a Samsung Galaxy or an iPhone 5. But in general you should keep your media queries as simple as possible. Everyday new devices are lauched and if you have dozen or more websites with very complex, device specific media queries you’ll have a hell of a job to keep everything up to date.
Simply put: every CSS rule.
You can make a ‘normal web page’ look like a native app on smartphones if you’d wish.
This table can be your guideline for your mediaqueries.
Screen width | Smallest screen height | In use worldwide |
1024 px | 768 px | 3% |
1280 px | 800 px | 11% |
1360 px | 768 px | 2% |
1366 px | 768 px | 35% |
1440 px | 900 px | 6% |
1600 px | 900 px | 6% |
1680 px | 1050 px | 3% |
1920 px | 1080 px | 20% |
2560 px and up | 1440 px | 1% |
You don’t need to write mediaqueries for every possible screen resolution. To keep things simple you could target four groups:
Those are the breakpoints as used by the very popular Twitter Bootstrap framework.