CSS Snippets: Media Queries

Published November 24, 2016 by CSS Newbies.

We’ve come to a point in web development where if you’re not creating or designing sites that are mobile friendly and responsive, you’re doing something wrong. Responsive design is no-longer optional, as more and more users continue to access the internet via their mobile devices. If you’re just getting started with mobile development (or even if you’ve been creating mobile web-apps for years), you may find this snippet of typical breaking points of different mobile devices super helpful to use in your media queries:

 

/* Smartphones (portrait and landscape) ----------- */</code></p>
<p class="line number2 index1 alt1"><code class="css plain">@media only </code><code class="css value">screen</code></p>
<p class="line number3 index2 alt2"><code class="css plain">and (min-device-width : </code><code class="css value">320px</code><code class="css plain">) and (max-device-width : </code><code class="css value">480px</code><code class="css plain">) {</code></p>
<p class="line number4 index3 alt1"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number5 index4 alt2"><code class="css plain">}</code></p>
<p class="line number6 index5 alt1"></p>
<p class="line number7 index6 alt2"><code class="css comments">/* Smartphones (landscape) ----------- */</code></p>
<p class="line number8 index7 alt1"><code class="css plain">@media only </code><code class="css value">screen</code> <code class="css plain">and (min-width : </code><code class="css value">321px</code><code class="css plain">) {</code></p>
<p class="line number9 index8 alt2"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number10 index9 alt1"><code class="css plain">}</code></p>
<p class="line number11 index10 alt2"></p>
<p class="line number12 index11 alt1"><code class="css comments">/* Smartphones (portrait) ----------- */</code></p>
<p class="line number13 index12 alt2"><code class="css plain">@media only </code><code class="css value">screen</code> <code class="css plain">and (max-width : </code><code class="css value">320px</code><code class="css plain">) {</code></p>
<p class="line number14 index13 alt1"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number15 index14 alt2"><code class="css plain">}</code></p>
<p class="line number16 index15 alt1"></p>
<p class="line number17 index16 alt2"><code class="css comments">/* iPads (portrait and landscape) ----------- */</code></p>
<p class="line number18 index17 alt1"><code class="css plain">@media only </code><code class="css value">screen</code> <code class="css plain">and (min-device-width : </code><code class="css value">768px</code><code class="css plain">) and (max-device-width : </code><code class="css value">1024px</code><code class="css plain">) {</code></p>
<p class="line number19 index18 alt2"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number20 index19 alt1"><code class="css plain">}</code></p>
<p class="line number21 index20 alt2"></p>
<p class="line number22 index21 alt1"><code class="css comments">/* iPads (landscape) ----------- */</code></p>
<p class="line number23 index22 alt2"><code class="css plain">@media only </code><code class="css value">screen</code> <code class="css plain">and (min-device-width : </code><code class="css value">768px</code><code class="css plain">) and (max-device-width : </code><code class="css value">1024px</code><code class="css plain">) and (orientation : </code><code class="css value">landscape</code><code class="css plain">) {</code></p>
<p class="line number24 index23 alt1"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number25 index24 alt2"><code class="css plain">}</code></p>
<p class="line number26 index25 alt1"></p>
<p class="line number27 index26 alt2"><code class="css comments">/* iPads (portrait) ----------- */</code></p>
<p class="line number28 index27 alt1"><code class="css plain">@media only </code><code class="css value">screen</code> <code class="css plain">and (min-device-width : </code><code class="css value">768px</code><code class="css plain">) and (max-device-width : </code><code class="css value">1024px</code><code class="css plain">) and (orientation : </code><code class="css value">portrait</code><code class="css plain">) {</code></p>
<p class="line number29 index28 alt2"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number30 index29 alt1"><code class="css plain">}</code></p>
<p class="line number31 index30 alt2"></p>
<p class="line number32 index31 alt1"><code class="css comments">/* Desktops and laptops ----------- */</code></p>
<p class="line number33 index32 alt2"><code class="css plain">@media only </code><code class="css value">screen</code> <code class="css plain">and (min-width : </code><code class="css value">1224px</code><code class="css plain">) {</code></p>
<p class="line number34 index33 alt1"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number35 index34 alt2"><code class="css plain">}</code></p>
<p class="line number36 index35 alt1"></p>
<p class="line number37 index36 alt2"><code class="css comments">/* Large screens ----------- */</code></p>
<p class="line number38 index37 alt1"><code class="css plain">@media only </code><code class="css value">screen</code> <code class="css plain">and (min-width : </code><code class="css value">1824px</code><code class="css plain">) {</code></p>
<p class="line number39 index38 alt2"><code class="css spaces">  </code><code class="css comments">/* Styles */</code></p>
<p class="line number40 index39 alt1"><code class="css plain">}</code></p>
<p class="line number41 index40 alt2"> 
Use these media queries to make sure that your design is sized correctly and has the right breaking points for as many devices as possible!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>